Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to access contents of NSDictionary from JSON data request
    primarykey
    data
    text
    <p>I'm trying to access the contents of a dictionary using the following code and can't get it to work for some reason.</p> <p>the <code>NSLog(@"self.userCommentsArray %@",self.userCommentsArray);</code> returns null</p> <p>thanks for any help with this.</p> <pre><code>NSData *jsonData = [NSData dataWithContentsOfURL:myURL]; NSDictionary *userCommentsDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&amp;error]; NSLog(@"userCommentsDictionary %@",userCommentsDictionary); // this works self.userCommentsArray = [[userCommentsDictionary objectForKey:@"from"] objectForKey:@"name"]; NSLog(@"self.userCommentsArray %@",self.userCommentsArray); </code></pre> <p>here's the nslog output for the dictionary:</p> <pre><code>userCommentsDictionary { data = ( { created = "2013-07-16T18:42:56+02:00"; from = { id = 27; name = "user-4"; }; id = 2553; message = "liquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum"; }, { created = "2013-07-16T18:42:56+02:00"; from = { id = 28; name = "user-5"; }; id = 2554; message = "x ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum"; }, { created = "2013-07-19T16:18:56+02:00"; from = { id = 24; name = "user-1"; }; id = 5125; message = test comment; }, { created = "2013-07-19T17:00:21+02:00"; from = { id = 24; name = "user-1"; }; id = 5126; message = "test comment "; } ); meta = { totalCount = 18; }; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload