How to get an array of JSON objects from NSData object [duplicate] How to get an array of JSON objects from NSData object [duplicate] objective-c objective-c

How to get an array of JSON objects from NSData object [duplicate]


If you're using iOS 5.0 and up, you can do this:

Objective-C:

NSError *error = nil;NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData:myNSData options:kNilOptions error:&error];if (error != nil) {    NSLog(@"Error parsing JSON.");}else {    NSLog(@"Array: %@", jsonArray);}

Swift:

do {    let jsonArray = try JSONSerialization.jsonObject(with: myNSData, options:[])    print("Array: \(jsonArray)")}catch {    print("Error: \(error)")}