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

我得到的NSString這個數據和我的問題是如何分割數據,分離到另一個NSString的,但我想作出逗號這麼多NSString的Xcode中分裂的NSString其他NSString的

+2

看着這些數據我想你會更好找一個JSON解析器,這應該給你一個NSDictionary或類似的遍歷數據結構。 –

+0

的數據是正確的,我只是想拆分文本之間,每個人到一個nsstring,不是所有的人到另一個nsstring,也許是一個數組,但多行數組,所以我可以使用一切單獨 –

回答

14

使用以下

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

好的非常感謝很多 –

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

感謝答案和我如何使用數組的索引?我怎麼能複製索引[1]到nsstring等? –

+0

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

+0

如果它適用於您接受它作爲答案... – Minakshi