How to add a string to JsonArray

I am trying to add string values ​​to a JsonArray and after that create a Json String to send it to the server.

I searched on google but did not find anything useful. Can someone tell me how to do this? Thanks

JSONArray list = new JSONArray(); list.put("Hello"); list.put("Hey"); 

After that I want to create a JSONString

+4
source share
2 answers

Plain:

 JSONArray list = new JSONArray(); list.put("Hello"); list.put("Hey"); String jsonString = list.toString() 

according to the docs, this should result in "[" Hello "," Hey "]"

+11
source

just use

list.toString(2)

this will give you a string in json

+1
source

All Articles