我用sbjson解析JSON, 這是JSON的,我試圖解析:異常 'NSInvalidArgumentException': - [__ NSArrayM objectForKey:]:無法識別的選擇發送到實例0x752c670
{"R":"0","S":"","T":"","M":[{"C00":"2013-08-16 17:35:03"}]}
,這是我的代碼:
NSString *response = [self post:@"9903" content:payload state:@""];
NSDictionary *dict = [response JSONValue];
NSString *result = [dict objectForKey:@"R"];
NSLog(@"result=%@",result);
if ([@"0" isEqualToString:result]) {
NSDictionary *msg = [dict objectForKey:@"M"];
NSString *C00 = [msg objectForKey:@"C00"];//here the exception Statement
NSString *tokenString = [NSString stringWithFormat:@"%@",C00];
NSLog(@"tokenString%@",tokenString);
return tokenString;
}else {
return nil;
}
異常日誌:
2013-08-16 17:45:44.902 VEP[4731:c07] -[__NSArrayM objectForKey:]: unrecognized selector sent to instance 0x7250300
2013-08-16 17:45:44.903 VEP[4731:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM objectForKey:]: unrecognized selector sent to instance 0x7250300'
什麼錯了嗎?謝謝你的幫助!
閱讀錯誤消息並將其與您的JSON數據進行比較。 (Spoiler:'[dict objectForKey:@「M」]'返回* array *,而不是* dictionary *。) –
Btw .:「JSON __NSArrayM objectForKey無法識別的選擇器」有*許多*谷歌命中描述(並解釋)正是你的問題。 –