Xcode将可变字典从JSON添加到可变数组

时间:2014-09-10 16:39:45

标签: json xcode nsmutablearray nsmutabledictionary

我有一个可变的数组故事,我试图添加一个JSON响应的副本,但它产生O故事,数组中没有任何内容。我究竟做错了什么? JSON对象格式正确,我可以单独显示每个组件,但不会添加到数组中。

NSString *str=@"http://www.foo.com/some.php";
NSURL *url=[NSURL URLWithString:str];
NSData *data=[NSData dataWithContentsOfURL:url];
NSError *error=nil;
NSMutableDictionary *response=[NSJSONSerialization JSONObjectWithData:data options:
             NSJSONReadingMutableContainers error:&error];

NSLog(@"Your JSON Object: %@", response);


NSLog(@"Location: %@", response[@"location"]);
NSLog(@"Service ID: %@", response[@"serviceID"]);
NSLog(@"Problem: %@", response[@"problem"]);

[stories addObject:[response copy] ];

NSLog(@"Workorders: %d", [stories count]);
NSLog(@"WO Defined: %@",stories);

1 个答案:

答案 0 :(得分:0)

你去......尝试这个

NSMutableArray *stories = [NSMutableArray array];