Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android JSONObject vs. GSON

Tags:

json

android

gson

I am not able to understand the difference between JSONObject and GSON for parsing JSON strings in Android.

Can somebody explain?

like image 864
May13ank Avatar asked Nov 14 '11 12:11

May13ank


People also ask

What is difference between JSON and GSON in Android?

JSON. simple is a Java toolkit for encoding and decoding JSON text. It's meant to be a lightweight and simple library that still performs at a high level. GSON is a Java library that converts Java Objects into JSON and vice versa.

What is difference between JSON object and JSON object?

This isnt base Java, those are Objects depending on the JSON-libary you are using. JSONObject is "native" to Android SDK, JsonObject is probably the one from Gson library, the one that I use. Two different package, don't work with both ;) choose one.

Which Java JSON library is best?

1. Jackson. Jackson is a multi-purpose Java library for processing JSON data format. Jackson aims to be the best possible combination of fast, correct, lightweight, and ergonomic for developers.

Is GSON faster than Jackson?

Last benchmarks Jackson was the winner, but this time GSON is by far the fastest, with JSONP being a close second and then followed by Jackson and then JSON. simple last. And again looking at the numbers from two different angles, here are the percentage results: GSON is a clear winner.


2 Answers

GSON can use the Object definition to directly create an object of the desired type. JSONObject needs to be parsed manually. Thats the main difference.

like image 83
Tim Avatar answered Sep 21 '22 22:09

Tim


as the others said, GSON should make mapping JSON to POJO much easier, BUT, the latest GSON version (as I write, 2.2.2) has serious issues with the latest Android API 17 (Android 4.2).

Check this for information: http://code.google.com/p/google-gson/issues/detail?id=496

If you are doing a new project now, and want it to be compatible with Android 4.2, either use an older GSON (1.7.1 works fine with Android 4.2, but is slower), or find another solution.

like image 34
Tech Engineer Avatar answered Sep 18 '22 22:09

Tech Engineer