Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create json Object with NSData in Objective C?

How to create json Object with NSData in Objective C. I'm having values in a NSData variable.

like image 499
Deepak Pillai Avatar asked Dec 26 '22 17:12

Deepak Pillai


1 Answers

You can use it like this in iOS 5 (if you are sure of your json structure you can directly use NSArray or NSDictionary doing a cast)

NSError *jsonError;
id jsonDictionaryOrArray = [NSJSONSerialization JSONObjectWithData:myData options:NULL error:&jsonError];
if(jsonError) {
    // check the error description
    NSLog(@"json error : %@", [jsonError localizedDescription]);
} else {
    // use the jsonDictionaryOrArray
}
like image 82
Moxy Avatar answered Jan 14 '23 08:01

Moxy