2010-01-06 43 views
1

我有一個JSON字符串,我轉變爲一個NSDictionary中,而我得到了關鍵的「人」的價值觀,以一個的NSDictionary:peopleDict的iPhone - 訪問的NSDictionary

NSDictionary *testDict = [jsonString JSONValue]; 
NSDictionary *peopleDict = [testDict objectForKey:@"people"]; 

一個NSLog的

NSLog(@"%@", peopleDict); 

回到我如下:

{ 
0 =  { 
    id = 1; 
    name = Doe; 
    date = "Fri Dec 04 13:50:30 +0200 2009"; 
}; 
1 =  { 
    id = 20; 
    name = Mr. T; 
    date = "Fri Nov 18 17:55:30 +0200 2009"; 
}; 
2 =  { 
    id = 100; 
    name = TestName; 
    date = "Mon Nov 30 12:00:10 +0200 2009"; 
}; 
} 

結果的數量,我知道(在這種情況下3)。 但我怎麼能訪問行0..2和鍵值? id是一個int值,命名一個字符串,日期也是一個字符串。

有誰知道嗎?

非常感謝&最好的問候。

回答

7
for (id key in peopleDict) { 
    NSLog(@"key: %@, value: %@", key, [peopleDict objectForKey:key]); 
} 

這裏有一個link to NSDictionary reference

你可能想看一看到:訪問鍵和值方法:

  • allKeys
  • allKeysForObject:
  • allValues
  • getObjects:andKeys:
  • objectForKey:
  • objectsForKeys:notFoundMarker:
  • valueForKey: