Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here are some more examples of how to create a json string in java:</p> <pre><code>public String createJSONArrayOfObjects() throws JSONException { JSONArray list = new JSONArray(); JSONObject obj = new JSONObject(); obj.put("name", "foo"); obj.put("num", new Integer(100)); obj.put("balance", new Double(1000.21)); obj.put("is_vip", true); obj.put("nickname", ""); list.put(obj); obj = new JSONObject(); obj.put("name" , "foo too"); obj.put("num", new Integer(200)); obj.put("balance", new Double(2000.21)); obj.put("is_vip", true); obj.put("nickname", ""); list.put(obj); return list.toString(); } public String mixingJSONArrayAndObjects() throws JSONException { JSONArray list1 = new JSONArray(); list1.put("foo"); list1.put(new Integer(100)); list1.put(new Double(1000.21)); JSONArray list2 = new JSONArray(); list2.put(true); JSONObject obj = new JSONObject(); obj.put("name", "foo"); obj.put("num", new Integer(100)); obj.put("balance", new Double(1000.21)); obj.put("is_vip", true); obj.put("nickname", ""); obj.put("list1", list1); obj.put("list2", list2); return obj.toString(); } public String createJSONArray() throws JSONException { JSONArray list = new JSONArray(); list.put("foo"); list.put(100); list.put(1000.21); list.put(true); return list.toString(); } public void createJSONArrayFromString(String anArray) throws JSONException { JSONArray list = new JSONArray(anArray); for (int i = 0; i &lt; list.length(); i++) { switch (i) { case 0: System.out.println(i + " " + list.getString(i)); break; case 1: System.out.println(i + " " + list.getInt(i)); break; case 2: System.out.println(i + " " + list.getDouble(i)); break; case 3: System.out.println(i + " " + list.getBoolean(i)); break; } } } public String createObject() throws JSONException { JSONObject obj = new JSONObject(); obj.put("name", "foo"); obj.put("num", new Integer(100)); obj.put("balance", new Double(1000.21)); obj.put("is_vip", true); obj.put("nickname", ""); return obj.toString(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload