Reputation: 5896
I am trying to add string values in JsonArray and after that create Json String to send it on server.
I was searching on google but I couldn't find anything helpful. Could anyone tell me how to this? Thanks
JSONArray list = new JSONArray();
list.put("Hello");
list.put("Hey");
After that I want create JSONString
Upvotes: 8
Views: 19417
Reputation: 15679
Simple:
JSONArray list = new JSONArray();
list.put("Hello");
list.put("Hey");
String jsonString = list.toString()
according to docs it should result in "["Hello", "Hey"]"
Upvotes: 16
Reputation: 2044
just use
list.toString(2)
this will give you the string in json
Upvotes: 1