2011-11-24 8 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"} 

i obtener estos datos con NSString y mi pregunta es cómo dividir los datos que separa a otro nsstrings, pero quiero hacer como comas tanto nsstringsXcode divide NSString a otros NSStrings

+2

en cuanto a los datos que creo que estaría mejor en busca de un analizador JSON, que deben darle una NSDictionary o similar para atravesar la estructura de datos. –

+0

los datos son correctos, solo quiero dividir el texto entre todos en un nsstring, no todos en otro nsstring, tal vez en un arreglo pero en un arreglo multilineal, así que puedo usar todo por separado –

Respuesta

14

Use la siguiente

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

bien muchas gracias –

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

gracias por el respuesta y ¿cómo puedo usar el índice de matriz? ¿Cómo puedo copiar el índice [1] a nsstring y etc.? –

+0

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

+0

Si funciona para usted, acéptelo como una respuesta ... – Minakshi