Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is different between JsonObject and JSONObject

Tags:

java

json

android

What is different between JsonObject and JSONObject?

I am little bit confuse JsonObject and JSONObject and when we use put, add and addproperty method.

thanks in advance.

like image 846
Alex Mark Avatar asked Jul 25 '16 13:07

Alex Mark


People also ask

Is JSONObject and JSONObject same?

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.

What is difference between JSON object and JSON string?

JSON is a string format. The data is only JSON when it is in a string format. When it is converted to a JavaScript variable, it becomes a JavaScript object.

What is the difference between JSON object and JSON array?

JSON defines only two data structures: objects and arrays. An object is a set of name-value pairs, and an array is a list of values.

What is the use of JSONObject?

JsonObject class represents an immutable JSON object value (an unordered collection of zero or more name/value pairs). It also provides unmodifiable map view to the JSON object name/value mappings. A JsonObject instance can be created from an input source using JsonReader. readObject() .


1 Answers

The Android SDK provides JSONObject. This can be used by importing org.json.JSONObject.

The documentation for JSONObject is here.

Any other variant will be from a library or linked project. The exmaple given by cricket_007 is JsonObject from the Gson libraries. This can be used by importing com.google.gson.JsonObject.

The documentation for JsonObject is here.

Note the difference in import statement for JSONObject and JsonObject - they are different classes in different packages. They can have different methods and functionality, take different parameters etc, but ultimately they will do the same or similar thing (holding a Json Object's contents). It is up to you which you use. The JavaDoc for each will describe how to use it, and there are plenty of resources online for each.

like image 71
biddulph.r Avatar answered Sep 19 '22 07:09

biddulph.r