Inge
0
Q:

convert json string to json object in java

JSONObject json = new JSONObject();

json.toString();
2
// Imagine we received this text from a web server:
'{ "name":"John", "age":30, "city":"New York"}'

// To convert text into a JavaScript object, use the JavaScript function JSON.parse():
var obj = JSON.parse('{ "name":"John", "age":30, "city":"New York"}');

// OR
var string = '{ "name":"John", "age":30, "city":"New York"}';
var obj = JSON.parse(string);
17
var person={"first_name":"Tony","last_name":"Hawk","age":31};
var personJSONString=JSON.stringify(person); 
27
try {
     JSONObject jsonObject = new JSONObject("{\"phonetype\":\"N95\",\"cat\":\"WP\"}");
}catch (JSONException err){
     Log.d("Error", err.toString());
}
1
I add GSON dependency in my POM --> It’s a json parser. That is
used to convert from java object to json and from json to java
object
SERIALIZATION: CONVERT JAVA OBJECT -> JSON
DE-SERIALIZATION: CONVERT JSON -> JAVA OBJECT
0

New to Communities?

Join the community