Difference between gson API and json class provided by Android.

4,277 views
Skip to first unread message

ravindra bhavsar

unread,
Feb 29, 2012, 1:20:34 AM2/29/12
to google-gson
Hi,

I m confuse about json class and gson API both use for parsing
purpose and i dont understand advantage of using gson API for
parsing.

json class needs json string when it aceess webservice or any
webservice return json string for parsing.
but if any web service that return java object instead of json string
then can we use gson API for parsing that java object in android.if
anybody knows then plz help me......

Karim Varela

unread,
Feb 29, 2012, 6:14:27 PM2/29/12
to googl...@googlegroups.com
I'm working on integrating GSON into our Android app as well. I think the main difference is that org.json just does simple json encoding/decoding and not full object data binding.

Jesse Wilson

unread,
Mar 1, 2012, 12:38:59 AM3/1/12
to google-gson
There are two JSON APIs on Android:

org.json is a simple, tree-style API. It's biggest weakness is that it
requires you to load the entire JSON document into a string before you
can parse it. For large JSON documents this may be inefficient.
http://developer.android.com/reference/org/json/package-summary.html

android.util.JsonReader/JsonWriter are low-level streaming APIs.
They're efficient but don't do databinding, so you need to write some
boilerplate code to use these. They're only available in Android 3+.
For earlier versions of Android the same API is available standalone
in Gson's stream package.
http://developer.android.com/reference/android/util/JsonReader.html

Gson's JsonReader and JsonWriter are derived from Android's JsonReader
and JsonWriter. I literally copied and pasted them from Android into
Gson one day, and try to keep them in sync as I optimize one or the
other.

Gson is the best API for JSON parsing on Android. It has a very small
binary size (under 200 KiB), does fast databinding, and has a simple
easy-to-use API. Android's built-in JSON libraries are also good. You
should use them if you aren't doing much JSON and don't need
databinding.

ravindra bhavsar

unread,
Mar 1, 2012, 12:41:45 AM3/1/12
to googl...@googlegroups.com
thanks for reply.
if i want parse web service data in json object then is it mandatory for that web service to return their data as json string? i mean web service need to provide their data as json string to convert / parsing into the json object in my android app.

--
You received this message because you are subscribed to the Google Groups "google-gson" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-gson/-/7v3ZfrQuicUJ.
To post to this group, send email to googl...@googlegroups.com.
To unsubscribe from this group, send email to google-gson...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-gson?hl=en.

ravindra bhavsar

unread,
Mar 1, 2012, 1:06:23 AM3/1/12
to googl...@googlegroups.com
hello jesse wilson,

Thanks for reply.I think your suggesion will be  very helpful for me.
can tell me? for parsing web service data into json object using Gson API in android application it must be necessary for that web service to return their data as json string.    

Ragav G

unread,
Aug 2, 2012, 12:29:07 AM8/2/12
to googl...@googlegroups.com
Hi friends,
Am stuck in combine json files.
See i have three json file in my android sd card or asset folder.I want to mrege three json file as a single json file and store on my local location.
This module am doing in android mobile app.

Note:GSON or Jackson

All ideas are welcome.
    Thanks in advance.

Regards
Ragav.G
Reply all
Reply to author
Forward
0 new messages