I am trying to create this JSON object on android. I am stuck on how to add a string array in the object.
A = {
\"class\" : \"4\" ,
\"name\" : [\"joh
As bhavindesai noted,
ArrayList list = new ArrayList();
list.add("john");
list.add("mat");
list.add("jason");
list.add("matthew");
JSONObject school = new JSONObject();
school.put("class","4");
school.put("name", new JSONArray(list));
is a much better and cleaner approach.
To import the right package you should write:
import org.json.simple.JSONArray;
on top of java class.
And if you are using Maven, add
com.googlecode.json-simple
json-simple
1.1
to pom.xml. Then, Download sources & dependencies and Reimport. I answered though I used commenting, since commenting screwed up the code indentation.