我試圖解析我的iOS應用程序的API。但是,由於某種原因,API返回JSON,我似乎無法解析(使用NSJSONSerialization)。由於我不知道player1和player2的名字,所以我不能使用objectForKey(在測試中,我知道player1是玩家的名字等)。所以我使用objectAtIndex導致崩潰,「 - [__ NSCFDictionary objectAtIndex:]:無法識別的選擇器發送到實例」。
JSON:- [__ NSCFDictionary objectAtIndex:]:無法識別的選擇器發送到實例
{
"id": "idnumb",
"numentrants": 2,
"entrants": {
"player1": {
"displayname": "player1",
"otherdata": 1234,
},
"player2": {
"displayname": "player2",
"otherdata": 5678,
}
}
}
的OBJ C:
NSError *jsonParsingError = nil;
NSDictionary *eventArray = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonParsingError];
for(int i = 0; i < [[eventArray objectForKey:@"entrants"] count]; i++)
{
NSArray *entrantsArray = [[eventArray objectForKey:@"entrants"] objectAtIndex:i];
NSLog(@"%@", entrantsArray);
}
由於
如果您是Google您的問題標題,那麼*第一個*引用是您的副本。 (或者,相反,你的是一個重複的。) – 2014-08-30 00:11:16
順便說一句,你應該去json.org和學習JSON語法。學習只需要5-10分鐘,而且知道它會讓你免於提出類似的重複問題。 – 2014-08-30 02:06:02
標記的副本上的信息沒有解決問題。但是,nzeltzer的allValues解決方案確實如此。 – eaofkaefaefa4fa4fa4f 2014-08-30 03:07:49