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

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -