0

我有一个 JSON 响应:

{"result":
         [
            {"id":"1","inviter":"someguy1","invitee":"test","group_id":"1","status":"2"},
            {"id":"2","inviter":"someguy2","invitee":"test","group_id":"1","status":"2"}
         ]
}

我正在尝试通过以下方式打印每个 dict 的所有值:

NSDictionary* res = [[json objectForKey:@"result"] objectAtIndex:0];

for(id object in res){
    NSDictionary *currentResult = (NSDictionary *)object;

    for(NSString *value in [currentResult allValues]){
        NSLog(@"value: %@", value);
    }
}

应用程序崩溃:

*由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSCFString allValues]:无法识别的选择器发送到实例 0x96d43b0”

for(NSString *value in [currentResult allValues])线。

有什么想法/建议/诀窍吗?

4

1 回答 1

1

你所拥有的是一个包含s的NSDictionarywith an 。NSArrayNSDictionary

试试这个(未测试):

NSArray *dictArray = [json objectForKey:@"result"];

for(NSDictionary *dict in dictArray){
    NSLog(@"dict = %@", [dict description]);
}
于 2012-11-11T02:45:22.283 回答