0

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"}

    ]}
Evan Mulawski
  • 54,662
  • 15
  • 117
  • 144
ddoor
  • 5,819
  • 9
  • 34
  • 41

2 Answers2

3

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"];
Evan Mulawski
  • 54,662
  • 15
  • 117
  • 144
0

Thanks mate, I was definately over complicating things:

The end code was this:

NSArray *valuesArray = [[playlist JSONValue] objectForKey:@"values"];
NSString *test = [[valuesArray objectAtIndex:0]valueForKey:@"Title"];    
NSLog(@"test = %@", test);

Now all I have to do is iterate through the set :)

Hector
  • 3,909
  • 2
  • 30
  • 46
ddoor
  • 5,819
  • 9
  • 34
  • 41