-4

我正在尝试解析以下 JSON 响应:http ://www.breaknews.com/api/v5/items?compact=false 。

这是我解析它的代码:

NSError* error = nil;
NSData* data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.breakingnews.com/api/v5/items?compact=false"] options:NSDataReadingUncached error:&error];
if (error) {
    NSLog(@"%@", [error localizedDescription]);
} else {

    NSError *e = nil;
    NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData: data options:kNilOptions error: &e];

    if (!jsonArray) {
        NSLog(@"Error parsing JSON: %@", e);
    } else {
        for(NSArray* item in jsonArray) {

            NSLog(@"Item: %@", item);

        }
    }

}

但是,我收到此错误:

-[__NSCFString objectAtIndex:]:无法识别的选择器发送到实例 0x101810a40

这是为什么 - 我做错了什么?

4

1 回答 1

2

Check the types of the objects you're using. You're assuming that everything is an NSArray, when in fact things in JSON can be NSArray, NSDictionary, NSString, NSNumber, and NSNull.

于 2013-04-20T20:45:07.917 回答