我有多个 JSON 对象,我必须为其检索值“title”。我成功地检索了每个“标题”值,但是,我不确定如何将所有这些标题值放入NSMutableArray
以后可以填充的值UITableView
中。
目前,storyTitle (a NSString
) 返回几个不同的字符串,但它们都是独立的。例如,控制台返回
2013-03-30 21:39:30.416 Appv0.1[32742:11303] (
"Boys\U2019 lacrosse display drive at Watsonville Jamboree"
)
2013-03-30 21:39:31.799 Appv0.1[32742:11303] (
"Volleyball teams currently undefeated midway through season"
)
2013-03-30 21:39:32.093 Appv0.1[32742:11303] (
"Wrestling season ends with a CCS victory and 2 state berths"
)
如何将这些字符串组合成一个数组?提前致谢!任何帮助,将不胜感激。
NSDictionary *res = [NSJSONSerialization JSONObjectWithData: returnData options:NSJSONReadingMutableLeaves error:&myError];
storyList = [NSMutableArray alloc];
storyTitle = [res objectForKey:@"title"];
//create array of storyTitles
NSString * story1 = [NSString stringWithFormat:@"%@", storyTitle];
//not sure how to do this array part
storyList = [NSMutableArray arrayWithObjects:story1,nil];
编辑:如果我这样做:
for(int i = 0; i < 5; i++){
storyTitle = [res objectForKey:@"title"];
NSString * story1 = [NSString stringWithFormat:@"%@", storyTitle];
[self.storyList addObject:story1];
}
控制台返回
array: (
"Boys\U2019 lacrosse display drive at Watsonville Jamboree",
"Boys\U2019 lacrosse display drive at Watsonville Jamboree",
"Boys\U2019 lacrosse display drive at Watsonville Jamboree",
"Boys\U2019 lacrosse display drive at Watsonville Jamboree",
"Boys\U2019 lacrosse display drive at Watsonville Jamboree",)
如何使阵列具有所有 3 个单独的故事?