Iphone 解析json时如何在数组中存储字符串
我正在使用SBJSON解析json url,一切正常。问题在于,如果m需要解析标记“title”,或者基本上解析任何其他标记,并将其存储在名为story的数组中。。我只能得到包含标记的最后一个值,而不是下面名为story的数组中存储的整个值列表的代码Iphone 解析json时如何在数组中存储字符串,iphone,objective-c,xcode,Iphone,Objective C,Xcode,我正在使用SBJSON解析json url,一切正常。问题在于,如果m需要解析标记“title”,或者基本上解析任何其他标记,并将其存储在名为story的数组中。。我只能得到包含标记的最后一个值,而不是下面名为story的数组中存储的整个值列表的代码 - (void)viewDidLoad { [super viewDidLoad]; jsonurl=[NSURL URLWithString:@"http://www.1040communications.net/sheeba/stepheni/
- (void)viewDidLoad {
[super viewDidLoad];
jsonurl=[NSURL URLWithString:@"http://www.1040communications.net/sheeba/stepheni/iphone/stephen.json"];
jsonData=[[NSString alloc]initWithContentsOfURL:jsonurl];
jsonArray = [jsonData JSONValue];
items = [jsonArray objectForKey:@"items"];
for (NSDictionary *item in items )
{
story = [NSMutableArray array];
description1 = [NSMutableArray array];
[story addObject:[item objectForKey:@"title"]];
[description1 addObject:[item objectForKey:@"description"]];
}
NSLog(@"booom:%@",story);}
这条线应该在for循环之外
story = [NSMutableArray array];
正在为字典中的每个项创建NSMutableArray,因此您只获得最后一个值。因此,您需要在输入for循环之前创建字典 应该在循环开始之前声明
故事
和描述1
。给我你的json输出日志