Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which json library to use on iphone to consume gson/jackson generated json

I need to build a java based JSON data API that will be accessed from mobile devices: Android, Iphone... I have narrowed down to these:

  • Server side data api - gson/jackson lib (pojo to json)
  • Android side - gson/jackson lib (json to pojo)
  • Iphone side - I googled & found that there are a bunch of frameworks Jsonkit, json-framework, touch json etc etc.

Question:

  • Can someone make a recommendation on the iphone side json library? The gson/jackson generated json output of the data api, must be consumable from iphone without any special tweaks to json structure

  • Is there any java Collection type that I should stay away from(on server side) to ensure the json is directly convertible to objective c objects?

  • Any other gotchas?

Note: I am aware of PhoneGap, titanuim & some equivalents - but not interested in them. Json is meant to be a universal format, but I have had cross-library issues earlier - hence this attempt to understand from people with prior experiance on the subject

Thanks!

like image 385
Ravi Avatar asked Oct 25 '11 16:10

Ravi


People also ask

What is JSON library?

JSON (JavaScript Object Notation, pronounced /ˈdʒeɪsən/; also /ˈdʒeɪˌsɒn/) is an open standard file format and data interchange format that uses human-readable text to store and transmit data objects consisting of attribute–value pairs and arrays (or other serializable values).

Is GSON and JSON the same?

The JSON format was originally specified by Douglas Crockford. On the other hand, GSON is a Java library that can be used to convert Java Objects into their JSON representation. It can also be used to convert a JSON string to an equivalent Java object.

What is the difference between JSON and Jackson?

JSON is a data format. Jackson is a Java library that can parse JSON.


2 Answers

  • I've been using RestKit Library in an iPhone App Project. It is a nice framework that supports HTTP request/response handling with (mostly REST) servers, JSON/XML parsers to help you with data translation and a JSON <-> Object Mapping system.

    It may supply your iPhone server communication needs (making requests to the server and receiving JSON responses from server and converting each of them into objective-c objects).

  • For RestKit, it only matters the objects of your JSON file. So you are free to use any class or collection in your server as far as you generate a valid JSON file as response.

  • It took me some time to learn how to use RestKit properly in my applications. But when you get used to it, it definitely saves you time, because it hides you the complexity of parsing JSON files for every request made to server. You are right in trying to pick a good JSON data handling API for your application.

    Another good thing about RestKit is its community. It has a GitHub, a Google Groups and an IRC channel. If you plan to use it as a framework, assigning to its mailing list is definitely a good idea.

Have a nice coding! ;P

like image 89
hbobenicio Avatar answered Nov 16 '22 03:11

hbobenicio


One of the best libraries to parse JSON in swift is EVReflection. It offers a very easy installation using CocoaPods or you can just download it and add to your project.

Usage is very easy and it works like GSON or Jackson in Android/Java.

Example using Alamofire:

class User : EVObject{
    // EVReflection does not support optionals!
    // So you have to not declare any optional vars
    var name = ""
    var surname = ""
}

Alamofire.request("Your API URL").responseString{
    response in
        let resString = response.result.value
        // assuming that resString = "{'name' : 'john', 'surname' : 'Doe'}"
        let user = User(json : resString)
}
like image 43
Medin Piranej Avatar answered Nov 16 '22 03:11

Medin Piranej