I have String variable called jsonString
:
{"phonetype":"N95","cat":"WP"}
Now I want to convert it into JSON Object. I searched more on Google but didn't get any expected answers...
I have String variable called jsonString
:
{"phonetype":"N95","cat":"WP"}
Now I want to convert it into JSON Object. I searched more on Google but didn't get any expected answers...
String to JSON using
Jackson
withcom.fasterxml.jackson.databind
:Assuming your json-string represents as this: jsonString = {"phonetype":"N95","cat":"WP"}
Using org.json library:
You can use
google-gson
. Details:Object Examples
(Serialization)
Note that you can not serialize objects with circular references since that will result in infinite recursion.
(Deserialization)
Another example for Gson:
Gson is easy to learn and implement, you need to know is the following two methods:
-> toJson() – convert java object to JSON format
-> fromJson() – convert JSON into java object
Output
Resources:
Google Gson Project Home Page
Gson User Guide
Example
For setting json single object to list ie
in to
List<Location>
use
jackson.mapper-asl-1.9.7.jar