iphone - exception 'NSInvalidArgumentException':-[__NSArrayM objectForKey:]: unrecognized selector sent to instance 0x752c670 -
this question has answer here:
i use sbjson parse json, json i'm trying parse :
{"r":"0","s":"","t":"","m":[{"c00":"2013-08-16 17:35:03"}]} and code:
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 exception statement nsstring *tokenstring = [nsstring stringwithformat:@"%@",c00]; nslog(@"tokenstring%@",tokenstring); return tokenstring; }else { return nil; } the exception log:
2013-08-16 17:45:44.902 vep[4731:c07] -[__nsarraym objectforkey:]: unrecognized selector sent instance 0x7250300 2013-08-16 17:45:44.903 vep[4731:c07] *** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[__nsarraym objectforkey:]: unrecognized selector sent instance 0x7250300' what's wrong? help!
because key 'm:' contain array of dictionary not dictionary. so, write a,
nsdictionary *msg = [[dict objectforkey:@"m"] objectatindex:0];
Comments
Post a Comment