Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode将可变字典从JSON添加到可变数组_Json_Xcode_Nsmutablearray_Nsmutabledictionary - Fatal编程技术网

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

Xcode将可变字典从JSON添加到可变数组,json,xcode,nsmutablearray,nsmutabledictionary,Json,Xcode,Nsmutablearray,Nsmutabledictionary,我有一个可变的数组故事,我试图向其中添加一个JSON响应的副本,但它会生成0个故事,而数组中没有任何内容。我做错了什么?JSON对象的格式正确,我可以单独显示每个组件,但它们不会添加到数组中 NSString *str=@"http://www.foo.com/some.php"; NSURL *url=[NSURL URLWithString:str]; NSData *data=[NSData dataWithContentsOfURL:url]; NSError *error=nil; N

我有一个可变的数组故事,我试图向其中添加一个JSON响应的副本,但它会生成0个故事,而数组中没有任何内容。我做错了什么?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);

好了,试试这个

NSMutableArray *stories = [NSMutableArray array];

当您使用web浏览器访问页面时,您能给出一个JSON的示例吗?您能解释一下如何初始化可变数组:
stories
Sorry,它位于文件NSMutableArray*stories的顶部;看起来故事没有初始化。因为Objective C允许向零对象发送消息,所以在调用[stories addObject:[response copy]]时不会遇到任何问题。