1
我有導致__NSCFDictionary objectAtIndex:
錯誤的數組字典。索引到數組字典時出現無法識別的選擇器錯誤
有人能告訴我爲什麼嗎?錯誤發生時,字典顯然至少有一個數組。
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。你可以看到 – iDev