简体   繁体   English

Objective-C JSON解析错误

[英]Objective-C JSON parsing error

I'm trying to parse this JSON Array: 我正在尝试解析此JSON数组:

http://www.ifanatic.hu/api/get_recent_posts/?dev=1 http://www.ifanatic.hu/api/get_recent_posts/?dev=1

But I get this error: 但是我得到这个错误:

    2012-07-15 22:31:59.038 JSONTest[610:f803] -[__NSCFDictionary indexOfObject:]: unrecognized selector sent to instance 0x6a92850
2012-07-15 22:31:59.040 JSONTest[610:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary indexOfObject:]: unrecognized selector sent to instance 0x6a92850'
*** First throw call stack:
(0x13d7052 0x1568d0a 0x13d8ced 0x133df00 0x133dce2 0x236b 0xa23a59 0xa21e94 0xa22eb7 0xa21e4f 0xa21fd5 0x966f6a 0x3989bbd 0x3a565ea 0x3980298 0x3a5616b 0x3980137 0x13ab97f 0x130eb73 0x130e454 0x130ddb4 0x130dccb 0x12c0879 0x12c093e 0x2ea9b 0x1cb8 0x1c15)
terminate called throwing an exception

Here is my source: 这是我的资料来源:

NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

NSArray* latestPosts = [responseString JSONValue];

NSDictionary* post = [latestPosts objectAtIndex:[latestPosts indexOfObject:0]];

NSString* title = [post objectForKey:@"title"];

label.text = [NSString stringWithFormat:@"Title: %@", title];

That JSON object's root element is translated to an NSDictionary when parsing the JSON. 解析JSON时,该JSON对象的根元素将转换为NSDictionary。 And NSDictionary doesn't respond to the 而且NSDictionary没有回应

indexOfObject:

message. 信息。 What you need to do is to use: 您需要做的是使用:

NSDictionary *post = [[latestPosts objectForKey:@"posts"] objectAtIndex:0];

etc. 等等

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM