Sandy
0
Q:

javascript convert string to json object

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
var jsonPerson = '{"first_name":"billy", "age":23}';
var personObject = JSON.parse(jsonPerson); //parse json string into JS object
34

New to Communities?

Join the community