How to convert JSON serialized data to NSDictionary

92,268

Solution 1

Please Try the following Code.

NSError* error;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData
                                                     options:kNilOptions 
                                                       error:&error];

NSArray* latestLoans = [json objectForKey:@"loans"];

NSLog(@"loans: %@", latestLoans);

Solution 2

Just in case anyone is here to see swift code:

NSData to NSDictionary

let dictionary:NSDictionary = NSKeyedUnarchiver.unarchiveObjectWithData(jsonData)! as NSDictionary

NSData to NSString

let resstr = NSString(data: res, encoding: NSUTF8StringEncoding)
Share:
92,268
Rajesh
Author by

Rajesh

Updated on April 05, 2020

Comments

  • Rajesh
    Rajesh about 4 years

    I have used this method,

    NSDictionary *jsonObject=[NSJSONSerialization 
           JSONObjectWithData:jsonData 
                      options:NSJSONReadingMutableLeaves 
                        error:nil];
    NSLog(@"jsonObject is %@",jsonObject);
    

    It's printing "jsonObject is null".
    Is there any problem with "error:nil".
    I am not using any url or connection methods.
    I have a json file and I want to display it in a table.