installing json-framework with iOS

392 Views Asked by At

This seems like a simple-stupid thing, but I can't get it to work. Here's the flow:

Download and unzip the json-framework package from GitHub. Create a new standard, Single View Application with XCode. Make a new group named 'JSON' in my project. Make a directory in my project directory named 'JSON', and copy the files from 'json-framework-master/Classes/*' into this directory. In the XCode project, drag the files I just copied into the 'JSON' group I created. The files are successfully added to the project. In my code, I add at the top:

#include "SBJSON.h"

in the app delegate launch method, I add this:

NSDictionary *myDict = [NSDictionary dictionaryWithObject:@"Hi" forKey:@"There"];
NSString *myString = [myDict JSONRepresentation];

This is just a simple test to make sure JSON is working correctly. Everything builds and compiles fine, but I get this error:

-[__NSDictionaryI JSONRepresentation]: unrecognized selector sent to instance 0x1d537b20  

I even tried adding the '-all_load' linker flag to both the project and the target, but that does nothing. I am building on an iPhone 5 with iOS 6.0.

Also I know that iOS5+ includes native JSON support, but I need to support older versions as well.

2

There are 2 best solutions below

0
Thibaut LE LEVIER On

You should try to use JSONKit instead of SBJSon.

you should also try to work with Cocoapods for theses kind of dependencies, and setup issues

0
Shaun Budhram On

It looks like the problem was that XCode is not automatically adding the .m files to the list of Compile Sources. I had to manually go into ->Targets->Build Phases->Compile Sources and manually add the .m file associated with JSON.

Seems like this shouldn't be the default.. maybe I accidentally set a config setting in XCode somewhere to make this the default behavior when adding files?