objective c - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectForKey:] -
my xml response:
{ "s:envelope" = { "s:body" = { "ns2:getmatchlistresponse" = { item = ( { answertime = { text = 30; }; challengerappealsgranted = { text = "0 of 16"; }; challengerhandle = { text = manish; }; challengermatchesplayed = { text = 93; }; challengerpic = { text = "image.png"; }; challengerscore = { text = 0; }; challengerlosses = { text = 0; }; challengerwins = { text = 4; }; handle1 = { text = sahni; }; handle1appealsgranted = { text = 5; }; handle1matchesplayed = { text = 84; }; handle1response = { text = pending; }; handle1score = { text = 0; }; handle1losses = { text = 0; }; handle1wins = { text = 1; }; handle2matchesplayed = { text = 0; }; handle2score = { text = 0; }; handle2losses = { text = 0; }; handle2wins = { text = 0; }; handle3matchesplayed = { text = 0; }; handle3score = { text = 0; }; handle3losses = { text = 0; }; handle3wins = { text = 0; }; idmatch = { text = 750; }; isappeal = { text = false; }; isfreeform = { text = false; }; ismultichoicequestion = { text = false; }; ispublic = { text = false; }; matchname = { text = ewtwert; }; matchstartthresholdtime = { text = "4 days 7 hrs"; }; matchstatus = { text = wait; }; matchtype = { text = private; }; noofplayers = { text = 2; }; priorityinlist = { text = 0; }; scoretowin = { text = 5; }; timeduration = { text = "5 days"; }; turnchangesin = { text = 0; }; }, { answertime = { text = 30; }; challengerappealsgranted = { text = "0 of 16"; }; challengerhandle = { text = manish; }; challengermatchesplayed = { text = 93; }; challengerpic = { text = "image.png"; }; challengerscore = { text = 0; }; challengerlosses = { text = 0; }; challengerwins = { text = 4; }; handle1matchesplayed = { text = 0; }; handle1score = { text = 0; }; handle1losses = { text = 0; }; handle1wins = { text = 0; }; handle2matchesplayed = { text = 0; }; handle2score = { text = 0; }; handle2losses = { text = 0; }; handle2wins = { text = 0; }; handle3matchesplayed = { text = 0; }; handle3score = { text = 0; }; handle3losses = { text = 0; }; handle3wins = { text = 0; }; idmatch = { text = 749; }; isappeal = { text = false; }; isfreeform = { text = false; }; ismultichoicequestion = { text = false; }; ispublic = { text = false; }; matchname = { text = gfhf; }; matchstartthresholdtime = { text = "4 days 6 hrs"; }; matchstatus = { text = wait; }; matchtype = { text = public; }; noofplayers = { text = 2; }; priorityinlist = { text = 0; }; scoretowin = { text = 5; }; timeduration = { text = "5 days"; }; turnchangesin = { text = 0; }; } ); "xmlns:ns2" = "http://services.tgs.com/"; }; }; "xmlns:s" = "http://schemas.xmlsoap.org/soap/envelope/"; }; }
i need value of key "matchstartthresholdtime". do:
nsdictionary *dictresult = [xmlreader dictionaryforxmlstring:responsestring error:nil]; nsdictionary *enveloper = [dictresult objectforkey:@"s:envelope"]; nsdictionary *body = [enveloper objectforkey:@"s:body"]; nsdictionary *profiledetails = [body objectforkey:@"ns2:getmatchlistresponse"]; nsmutablearray *items = [profiledetails objectforkey:@"item"]; // nslog(@"items===>%@",items); nsdictionary *temp1; for(temp1 in items) { thresholdtime = [nsstring stringwithformat:@"%@",[[temp1 objectforkey:@"matchstartthresholdtime"]objectforkey:@"text"]];...thresholdtime nsstring object.......and line causes exception //nslog(@"time is===>%@",[[temp1 objectforkey:@"matchstartthresholdtime"]objectforkey:@"text"]); }
what problem here?
temp1 contains nsstring
object , not nsdictionary
, expect.
when dealing json wise (double) check if received object of type expect. use
if ([temp1 iskindofclass:[nsdictionary class]]) ...
or so.
Comments
Post a Comment