Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert JsonObject to String

Tags:

java

string

{     "data":      {         "map":         {             "allowNestedValues": true,             "create": "2012-12-11 15:16:13",             "title": "test201212110004",             "transitions": []         }     },     "msg": "success",     "code": "0" } 

Above is a JsonObject, the data is a JsonObject.

How to convert it to a String like "msg":"success" as you know, i can't directly add a double quotes outside data's value.

like image 452
Jay Zhang Avatar asked Jul 15 '13 09:07

Jay Zhang


People also ask

How do I convert a JSON object to a string?

Use the JavaScript function JSON. stringify() to convert it into a string. const myJSON = JSON. stringify(obj);

How do you turn an object into a string?

We can convert Object to String in java using toString() method of Object class or String. valueOf(object) method. You can convert any object to String in java whether it is user-defined class, StringBuilder, StringBuffer or anything else.

How do you pass a JSON object into a string in Java?

JSONObject json= (JSONObject) JSONValue. parse(jsonData); JSONObject data = (JSONObject) json. get("data"); After you have parsed the json data, you need to access the data object later get "map" data to json string.


1 Answers

There is an inbuilt method to convert a JSONObject to a String. Why don't you use that:

JSONObject json = new JSONObject();  json.toString(); 
like image 105
Tanu Garg Avatar answered Oct 12 '22 23:10

Tanu Garg