【发布时间】:2012-11-19 23:43:57
【问题描述】:
我有一个导致__NSCFDictionary objectAtIndex: 错误的数组字典。
谁能告诉我为什么?发生错误时,字典显然至少有 1 个数组。
NSError *error;
responseString = [[NSString alloc] initWithData:self.responseData2 encoding:NSUTF8StringEncoding];
/* response string contains this:
{"words":
{
"word": {"rowsreturned":0,"id":"-1","date":"","word":"","term":"","definition":"","updated_on":""}
},
"status":"",
"rowsreturned":""
}
*/
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:self.responseData2 options:kNilOptions error:&error];
NSArray *todaysWord = [[json objectForKey:@"words"] objectForKey:@"word"];
//error here -[__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance
NSDictionary *word = [todaysWord objectAtIndex:0];
【问题讨论】:
-
[[json objectForKey:@"words"] objectForKey:@"word"];正在返回字典而不是数组。尝试在该行之后添加一个 NSLog。你可以看到它
标签: objective-c ios json nsdictionary