Reputation: 1123
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 String[]={"stringone","stringtwo"]
it passed in something weird {"userids":"[Ljava.lang.String;@406fe4b8"}
how should I be constructing my JSON array if not by using string arrays?
Thanks
Upvotes: 3
Views: 6953
Reputation: 15434
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));
Upvotes: 10
Reputation: 9439
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.
Upvotes: 3