{ "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.
Use the JavaScript function JSON. stringify() to convert it into a string. const myJSON = JSON. stringify(obj);
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.
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.
There is an inbuilt method to convert a JSONObject to a String. Why don't you use that:
JSONObject json = new JSONObject(); json.toString();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With