I'm still learning JSON, and using SBJSON. How would I go about taking an NSDictionary and converting it into a JSON object similar to this:
{"id":"123","list":"456","done":1,"done_date":1305016383}
I'm still learning JSON, and using SBJSON. How would I go about taking an NSDictionary and converting it into a JSON object similar to this:
{"id":"123","list":"456","done":1,"done_date":1305016383}
Use the category that SBJSON adds to NSDictionary:
NSString *jsonString = [dictionary JSONRepresentation];
Just name the keys and values appropriately in the dictionary and SBJSON will do the work for you
There is a JSON-API (since iOS5 and OS X 10.7) in the official iOS-SDK it's called:
+ (NSData *)dataWithJSONObject:(id)obj
options:(NSJSONWritingOptions)opt
error:(NSError **)error
See Guillaume's post for more information how to use it: https://stackoverflow.com/a/9020923/261588
Works like a charm.
For those that are using JSONKit instead of SBJSON:
JSONKit also provides a category for NSDictionary
NSString *jsonString = [dictionary JSONStringWithOptions:JKSerializeOptionNone error:nil]