Create a JSONArray in Java
android, java, json
Solution
But how can I create a JSONArray and insert it to the JSONObject?
You can create JSONArray same like you have tried to create JSONObject.
Creating time:
For example:
JSONArray myArray = new JSONArray();
JSONObject j = new JSONObject();
j.put("key",value);
j.put("array",myArray);
Retrieving time:
you can fetch the value of String or JSONObject or any by their key name. For example:
JSONArray myArray = objJson.getJSONArray("array");
Problem
How can I create a JSONArray, since creating a JSONObject is quite simple: ``` JSONObject j = new JSONObject(); j.put("key",value); ``` Right now I can put another string in the JSONObject, or a string representation of a JSONObject. But how can I create a JSONArray and insert it to the JSONObject?