我使用sbjson来解析json, 这是我试图解析的Json:
{"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'
怎么了?谢谢你的帮助!
答案 0 :(得分:3)
因为您的密钥'M:'
不仅包含字典数组而且包含字典。所以,把它写成一个,
NSDictionary *msg = [[dict objectForKey:@"M"] objectAtIndex:0];