Reputation: 14934
I found this article about parsing JSON response from a URL request i iOS: http://www.raywenderlich.com/2965/how-to-write-an-ios-app-that-uses-a-web-service.
The article uses JSON Framework. I've downloaded the newest "SBJson_v3.0.4.zip" from the webpage and dragged in into a new group in my project. But then the build returns 62 errors like:
Does anybody know why? Is the JSON Framework not compatible with the newest Xcode?
Upvotes: 3
Views: 2783
Reputation: 1878
in your project settings, go to build phases and click on compile sources, you would get a bunch of .m files which are nothing but your project files. Click on the compiler flags colums for the corresponding file for which you need to disable ARC and type in -fno-objc-arc . Also, if your project doesn't supports ARC but you need to enable ARC in few files you can follow the same procedure but this time type in -fobjc-arc
Now you can use any json kit. No need to worry about the format. But i would strongly recommend to try out apple's inbuilt NSJSonSerialization methods and then go for third party json kits if not satisfied with Apple.
There are loads of them available on github along with their documentation . The one which i am currently using in my project is johnezang-jsonkit
Hope this helps you
Upvotes: 0
Reputation: 3939
The newest SBJSON has ARC support.
https://github.com/stig/json-framework
Upvotes: 1
Reputation: 13694
You need to disable the Automatic Reference Counting for those specific files provided in the package. If you go to the Project Settings -> Your Target -> Build Phases Tab and expand the Compile Sources arrow you'll see all your project files.
Under the ones that belong to SBJSON you need to add the -fno-objc-arc
compiler flag (find the file, double click on the right bit of the table and it'll bring up a box where you can add the compiler flags)
SBJSON is compatible with the latest SDK but it is not compatible with the Automatic Reference Counting enabled in the latest SDK which is why you get these errors.
Upvotes: 4
Reputation: 29975
Since iOS 5, iOS has its own JSON parser (thank you Twitter!)
NSError *err = nil;
id result = [NSJSONSerialization JSONObjectWithData:data options:0 error:&err];
Do make sure to check the type of the output - it can be anything from a string to a number to a dictionary to an array.
Upvotes: 12