3

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

2 Answers 2

10

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));
Sign up to request clarification or add additional context in comments.

Comments

3

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.