Monday, December 15, 2008

JSON framework with iPhone SDK 2.2

This is something that has cost me several hours after I upgraded to iPhone SDK 2.2. I have also documented it in the iPhone Discussion Forum but here is a brief summary.

If you going to use the JSON framework with the iPhone SDK 2.2 then there will be some problems. I could no longer link the framework to my application. For some reason Apple has changed the code signing behaviour. To get around it you need to add the JSON framework source code to your XCode project. 

1. Get the source code from:

svn checkout http://json-framework.googlecode.com/svn/trunk/ json-framework-read-only

2. Then copy that source code into your project directory (or use XCode add existing file...). 
3. Where you used :
#include <JSON/JSON.h> 
now you have to use:
#include "JSON.h"

and (as Dom pointed out)
#import "SBJSON.h"
#import "NSObject+SBJSON.h"
#import "NSString+SBJSON.h"

4. Build should be OK now.

Check out also http://jtribe.blogspot.com/2008/11/json-and-restful-web-services-on-iphone.html for more JSON / iPhone information.

4 comments:

Dom said...

Thanks for this Armin, I was having issues and couldn't work out what the problem was (obj-c/xcode newbie). I really appreciate your blog.

Dom said...

I have also found that you need to change the import instructions in the JSON.h header to the following:

#import "SBJSON.h"
#import "NSObject+SBJSON.h"
#import "NSString+SBJSON.h"

I seem to have it working now.

Armin Kroll said...

Thanks Dom,
I must have forgotten the three imports. Will add them to the main blog entry.

Michael said...

Thanks a lot :) worked great!!!