How to use TouchJSON in your Cocoa or Cocoa Touch application.Setup your projectCopy the source files within TouchJSON/Source to your project. The easiest way is to open both projects in Xcode, then drag and drop. Make sure to check "Copy items into destination groups folder (if needed)." To transform JSON to objectsPut #import "CJSONDeserializer.h" in your file. Here is a code sample: NSString *jsonString = @"yourJSONHere";
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF32BigEndianStringEncoding];
NSError *error = nil;
NSDictionary *dictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error];} Note that if you don't care about the exact error, you can check that the dictionary returned by deserializeAsDictionary is nil. In that case, use this code sample: NSString *jsonString = @"yourJSONHere";
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF32BigEndianStringEncoding];
NSDictionary *dictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:nil]; To transform objects to JSONPut #import "CJSONSerializer.h" in your file. Here is a code sample: NSDictionary *dictionary = [NSDictionary dictionaryWithObject:@"b" forKey:@"a"];
NSString *jsonString = [[CJSONSerializer serializer] serializeObject:dictionary];
|
I've created TouchCode? Dev Google Group. This is now the preferred forum for TouchCode? related development questions: http://groups.google.com/group/touchcode-dev