开发者

how to convert json object to string in android..?

开发者 https://www.devze.com 2023-01-22 17:52 出处:网络
I want to convert from JSONObject {\"CNo\":80,\"CName\":\"ganesh\",\"CMail开发者_C百科\":\"ganesh@ganesh.com\",\"CMailType\":\"home\",\"CPhNo\":9878987776,\"CPhNoType\":\"home\",\"ClientNo\":1}

I want to convert from JSONObject

{"CNo":80,"CName":"ganesh","CMail开发者_C百科":"ganesh@ganesh.com","CMailType":"home","CPhNo":9878987776,"CPhNoType":"home","ClientNo":1}

to

{\"CNo\":80,\"CName\":\"ganesh\",\"CMail\":\"ganesh@ganesh.com\",\"CMailType\":\"home\",\"CPhNo\":9878987776,\"CPhNoType\":\"home\",\"ClientNo\":1}


Try to use toString() on your JSON object


I hope this helps. Just learnt it yesterday :)

JSONObject foo = yourJSONOject;
String uid = foo.get("CNo").isString().toString();
String type = foo.get("CName").isString().toString();
.
. //for each Key field.

I am not sure why you have put the escapes in the string, but you can call append() and get the OP as you want it.


Below code will convert the given JsonObject to string.

Gson gson = new Gson();
String bodyInStringFormat = gson.toJson(passYourJsonObjectHere);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号