I am trying to create an array like this [\"stringone\",\"stringtwo\"]
and pass it to the webserver. When I tried doing making it with a string array like Str
If you want to create JSONArray
from List
or array, you can use constructor, which takes Collection
:
String[] data = {"stringone", "stringtwo"};
JSONArray json = new JSONArray(Arrays.asList(data));
The easiest way is to create a JSONArray object and use the put method(s) to add any Strings you want. To output the result, just use the toString() method.