banditKing
banditKing

Reputation: 9579

converting JSON to NSDictionary or NSArray - iOS

I have this bit of code:

[self.vManager playersNearLocation:userLocation
                             block:^(NSSet *players, NSError *error)
    {
        if(players && [players count])
        {
            NSLog(@"Success in getting players");
            /* TO DO
              Convert JSON to Objective C object here
            */   
        }else{
            NSLog(@"Failed to get players");
        }
    }];

I am receiving JSON from the server, how do I convert it to a Dictionary or array object. I dont want to use any external libraries, is there a native way?

Thanks

Upvotes: 0

Views: 1508

Answers (2)

Tomasz Dubik
Tomasz Dubik

Reputation: 641

Try NSJSONSerialization and method

+ (id)JSONObjectWithData:(NSData *)data options:(NSJSONReadingOptions)opt error:(NSError **)error

Upvotes: 3

V-Xtreme
V-Xtreme

Reputation: 7333

Its very easy to parse json if you have SBJSON library :SBJSON

Include this library in your project .Import json.h and you can parse json as follow

   SBJSON *parser=[[SBJSON alloc]init];

NSDictionary * dictionary = [parser objectWithString:responseString];

Upvotes: 0

Related Questions