How to extract the actual NSString from json object as NSArray

Posted by Toran Billups on Stack Overflow See other posts from Stack Overflow or by Toran Billups
Published on 2010-12-31T14:52:20Z Indexed on 2010/12/31 14:53 UTC
Read the original article Hit count: 214

Filed under:
|
|

I'm working with a large set of json and really just need the NSString representation of what's inside the NSArray -including all the { }

My question is this - is their a better way than simply looping through each NSArray inside the main NSArray and outputting the description one by one?

ie- the below is a start to this process but it's very brittle meaning I need to know each item inside the hat {} and this isn't something I actually care about. I just need the json string to move forward.

The working code is below (thank you in advance!)

NSString* responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    [responseData release];
  NSArray* json = [responseString JSONValue];
  NSArray* item = [json valueForKeyPath:@"d.data"];
  NSArray* hatjson = [item objectForKey:@"hat"];

  NSMutableString * result = [[NSMutableString alloc] init];
  for (NSObject * obj in hatjson)
  {
    [result appendString:[obj description]];
  }
  NSLog(@"the hat json is .. %@", result);

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c