2012-11-11 66 views
0

我有一個JSON響應:枚舉NSDictionary的NSDictionary;每提取元素的NSDictionary某個鍵

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

我試圖通過打印出每個字典的所有值:

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])行。

任何想法/建議/知道嗎?

回答

1

你有什麼是NSDictionaryNSArray其中包含NSDictionary s。

試試這個(未測試):

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

for(NSDictionary *dict in dictArray){ 
    NSLog(@"dict = %@", [dict description]); 
} 
+0

謝謝,非常完美。 – samuelsaumanchan