I know there are a few frameworks to parse JSON, but how can I generate a JSON string in Objective-C? Will it be something I would have to write myself, or is there something simple already out there?
A:
TouchJSON includes a mechanism to take a dictionary and produce JSON from it:
http://github.com/schwa/TouchJSON
The example code from that page:
NSDictionary *dictionary = [NSDictionary dictionaryWithObject:@"b" forKey:@"a"];
NSError *error = NULL;
NSData *jsonData = [[CJSONDataSerializer serializer] serializeObject:dictionary error&error];
Kendall Helmstetter Gelner
2010-09-19 18:56:19
A:
The interface for this framework seems pretty straight forward to use for generating JSON.
imaginaryboy
2010-09-19 19:01:27
+3
A:
I personally like json-framework
's use of categories on NSObject
over having to go through TouchJSON
's CJSONDataSerializer
interface.
NSDictionary *dict = [NSDictionary dictionaryWithObject:@"b" forKey:@"a"];
NSString *json = [dict JSONRepresentation];
Jacob Relkin
2010-09-19 19:07:44