Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: userc865b
Added: Mar 17, 2018 6:01 PM
Views: 18
Tags: java
get and access jsonArray by index
  1.     public static void main(String[] args) throws JSONException {
  2.  
  3.  
  4.         JSONObject jsonObject=new JSONObject("{\n" +
  5.                 "    \"ID\":\"test\",\n" +
  6.                 "    \"sports\": [\n" +
  7.                 "        \"volley-ball\",\n" +
  8.                 "        \"badminton\"\n" +
  9.                 "    ]\n" +
  10.                 "}");
  11.         //jsonObject.put("test","value1");
  12.  
  13.  
  14.        // jsonObject.put("id",0);
  15.         System.out.println(jsonObject.getJSONArray("sports").get(1));