asp.net - how can i get out the values from json and show them in NSLog -
hello created json string webservice , want output name , description show in nslog. how can that. heres code far:
dic = [nsjsonserialization jsonobjectwithdata:result options:kniloptions error:nil]; nslog(@"results %@",[nsstring stringwithformat:@"%@",[[dic objectforkey:@"d"]objectforkey:@"name"]]); i error:
-[__nscfstring objectforkey:]: unrecognized selector sent instance 0x6b50f30 when make nslog dictionary this:
{ d = "{ \n \"name\": \"apple\", \n \"beschreibung\": \"steve jobs ist tot\"}"; } my json string werbservice looks this:
string json = @"{ ""name"": ""apple"", ""beschreibung"": ""steve jobs ist tot""}";
doing kind of nested logging:
nslog(@"results %@",[nsstring stringwithformat:@"%@",[[dic objectforkey:@"d"]objectforkey:@"name"]]); is tricky. i'm guessing whatever object "d" returning isn't nsdictionary object, perhaps nsarray instead?
try this:
nsdictionary * dic = [nsjsonserialization jsonobjectwithdata:result options:kniloptions error:nil]; // gives whole nsdictionary output: nslog( @"results %@", [dic description] ); // dictionary corresponds key "d" nsdictionary * ddic = [dic objectforkey: @"d"]; if(ddic) { nsstring * nameobject = [ddic objectforkey: @"name"]; if(nameobject) { nslog( @"object key 'name' %@", nameobject ); } else { nslog( @"couldn't object associated key 'name'" ); } } else { nslog( @"couldn't object associated key 'd'") ); } and see if helps figure out @ level , @ object assumptions breaking.
Comments
Post a Comment