我正在尝试解析从以下链接返回的 JSOn:
https://icansolvecouk1.fatcow.com/prco303/loginjson.php?nickname=maggie&password=maggie
这是:
[{"sent":"2013-05-12 09:32:14","sender":"1","recipient":"1","message":"Hey hey hey"},{"sent":"2013-05-12 16:39:02","sender":"2","recipient":"1","message":"Another message"}]
在 obj-c 中使用以下代码:
NSDictionary *user = [result JSON];
NSLog(@"NSDictionary returned: %@",user);
NSArray* arrayOfReturnedItems = [user objectForKey:@"message"];
NSLog(@"Array returned: %@",[arrayOfReturnedItems objectAtIndex:0]);
NSDictionary 成功存储了 JSON 值,但稍后会出现错误。我对 Obj-C 和 JSON 非常陌生,因此不胜感激。我检查了 jsonlint.com,它说它是有效的,但我相信我得到错误的原因是我有效地拉回了两个数组(从那个 URL)但没有正确解析它。我可以访问为 JSON 提供服务的服务器,所以也许我需要在那里进行更改?
在我继续之前花了半天时间搜索这个网站寻求帮助,所以希望我能得到结果!
谢谢
来自 xcode 的错误:
2013-05-12 23:37:20.096 SecureComms[27240:1307]-[__NSArrayM objectForKey:]:无法识别的选择器发送到实例 0x8957e30 2013-05-12 23:37:20.097 SecureComms[27240:1307] * 由于应用程序终止uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM objectForKey:]: unrecognized selector sent to instance 0x8957e30' * First throw call stack: (0x1c98012 0x10d5e7e 0x1d234bd 0x1c87bbc 0x1c8794e 0x47dc 0x4399 0xbd8cf8 0xb4075a 0xb0e453 0xb0e164 0xb9aa31 0x49fc53f 0x4a0e014 0x49ff2e8 0x49ff450 0x91758e72 0x91740d2a) libc ++abi.dylib:终止调用抛出异常