Search code examples
iphonesbjson

SBJson parsing help iphone


im currently trying to parse some json data on the iphone.

I have been trawling the web for examples, but none seem to suit my purpose, i am using SBJson.

What I want is to be able to get an NSArray of Titles, Artisits, Status, etc. so that I can display them on a table view. Any help would be great, so far all i get is an array of "Values".

    JSON = {"values":
    [
      {"Status":"N", "Filename":"RD207T04", "Title":"Simple Man (Explicit)", "Artist":"DIAFRIX F/DANIEL MERRIWE", "Release":"May11"}, 

      {"Status":"N", "Filename":"CR221T27", "Title":"Midnight City", "Artist":"M83", "Release":"Dec11"}, 

      {"Status":"N", "Filename":"ED211T03", "Title":"I\"ll Be Your Man", "Artist":"JAMES BLUNT", "Release":"Jul11"}

    ]}

Solution

  • You don't want an array of titles, artists, etc. You want the array of NSDictionarys represented by the values key. Then you can do:

    cell.textLabel.text = [[valuesArray objectAtIndex:indexPath.row]valueForKey:@"Title"]];
    

    inside your cellForRowAtIndexPath: delegate method. If you do not have this already, this is how to get that array:

    NSArray *valuesArray = [[myJsonString JSONValue]objectForKey:@"values"];