2011-11-24 3 views
6
{"Title":"Chatroom","Year":"2010","Rated":"R","Released":"11 Aug 2010","Genre":"Drama, Thriller","Director":"Hideo Nakata","Writer":"Enda Walsh, Enda Walsh","Actors":"Aaron Johnson, Imogen Poots, Matthew Beard, Hannah Murray","Plot":"A group of teenagers encourage each other's bad behavior.","Poster":"http://ia.media-imdb.com/images/M/[email protected]@._V1._SX320.jpg","Runtime":"1 hr 37 mins","Rating":"5.3","Votes":"1000","ID":"tt1319704","Response":"True"} 

ottengo questi dati con NSString e la mia domanda è come dividere i dati che, separa a un altro nsstrings, ma voglio fare come virgole tanto nsstringsXcode diviso NSString ad altri NSStrings

+2

guardando i dati penso che sarebbe meglio alla ricerca di un parser JSON, che dovrebbe dare un NSDictionary o simile per attraversare la struttura dei dati. –

+0

i dati sono corretti, voglio solo dividere il testo tra, tutti su una stringa, non tutti su un'altra stringa, magari su un array ma su un array multilinea così posso usare tutto separato –

risposta

14

Usa questo

NSString *str; //Pass your string to str 
NSArray *array = [str componentsSeparatedByString:@","]; 

for(int i = 0; i < [array count]; i++) { 
    // Here just take strings one by one 
} 
+0

ok grazie mille –

1
NSString *string= //pass the string whatever you want. 
    NSArray *splitArray = [string componentsSeparatedByString:@","]; //it separates the string and store it in the different different indexes. 

Ex: 
    NSString *str= @"one,two,three"; 
    NSArray *array = [str componentsSeparatedByString:@","]; //it separates the string and store it in the different different indexes(one is at index 0 ,two is at index 1 and three is at index 2). 
+0

grazie per il risposta e come posso usare l'indice dell'array? come posso copiare l'indice [1] in nsstring ed ecc.? –

+0

NSString * secondString = [array objectAtIndex: 1]; – Tendulkar

+0

Se ha funzionato per te, accettalo come risposta ... – Minakshi