ios - parsing json and getting exception, reason: '-[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0x7b1c7630 -
i trying value particular key dictionary [__nscfarray objectforkey:]: unrecognized selector sent instance
- (void)listcaredmemberssuccessresponse:(nsdictionary *)response { [self hideactivityview]; if ([[response valueforkey:@"status"] caseinsensitivecompare:nslocalizedstring(@"success", nil)] == nsorderedsame) { nsdictionary *maindict = [response objectforkey:@"data"]; nsarray *detailsarray = [maindict objectforkey:@"text"]; [appdelegate.proxieslistarr addobjectsfromarray:[parsermanager parselistcaredmembers:detailsarray]]; } else { [[classobjects sharedcenter] showcustomalert:@"" message:nslocalizedstring(@"proxies_failureresponse", nil)]; }
this json response:
{"status":"success","data":[{"alias":"1-0","id":80,"icon":"","items":[],"params":{},"text”:”text1”,”type":"group","width":"170"},{"alias":"1-1","id":8000102,"icon":"","items":[],"params":{},"text”:”text2”,”type":"group","width":"170"}]}
the problem have nsarray
not nsdictionary
. nsarray
has count of 1 , contains nsdictionary
.
this line wrong
nsarray *detailsarray = [maindict objectforkey:@"text"];
nsarray *wrapper= [[nsjsonserialization jsonobjectwithdata:webdata options:0 error:nil]objectforkey:@"data"]; (nsdictionary *temp in wrapper) { nsstring *text=[temp objectforkey:@"text"]; //text may nsstring type // rest of code }
update
if ([[response valueforkey:@"status"] caseinsensitivecompare:nslocalizedstring(@"success", nil)] == nsorderedsame) { nsarray *maindict = [response objectforkey:@"data"]; (nsdictionary *temp in maindict) { nsstring *text=[temp objectforkey:@"text"]; //text may nsstring type // rest of code } }
Comments
Post a Comment