【发布时间】:2014-01-02 09:43:20
【问题描述】:
在我的应用程序中,我使用 JSON 解析数据
NSString * urlString=[NSString stringWithFormat:@"http://userRequest?userid=bala@gmail.com&latitude=59.34324&longitude=23.359257"];
NSURL * url=[NSURL URLWithString:urlString];
NSMutableURLRequest * request=[NSMutableURLRequest requestWithURL:url];
NSError * error;
NSURLResponse * response;
NSData *data=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString * outputData=[[NSString alloc]initWithData:data encoding:NSASCIIStringEncoding];
NSLog(@"%@",outputData);
SBJsonParser *jsonParser = [SBJsonParser new];
NSDictionary *jsonData = (NSDictionary *) [jsonParser objectWithString:outputData error:nil];
NSLog(@"%@",jsonData);
NSInteger success = [(NSNumber *) [jsonData objectForKey:@"success"] integerValue];
此代码执行后,在我的日志中打印为
({
latitude = "0.000000000000000";
longitude = "0.000000000000000";
username = sunil;
},
{
latitude = "80.000000000000000";
longitude = "30.000000000000000";
username = arun;
})
但是在运行时,应用程序崩溃了,因为
'NSInvalidArgumentException', reason: '-[__NSArrayM objectForKey:]: unrecognized selector sent to instance 0x910d8d0'
【问题讨论】:
-
上面的代码很好,错误在你代码的其他地方。请向我们展示您的数组的实例化以及您尝试访问数组中数据的代码,因为您试图在您的
NSMutableArray上调用一个仅适用于NSMutableDictionary的方法 -
哦,对不起,我会更新的
-
据我所知,在 json 中使用 ':' 而不是 '='.. 如果我错了请告诉我
-
@achievelimitless,我得到了答案,谢谢你
标签: ios iphone json invalid-argument