Android JSONObject : add Array to the put method

前端 未结 2 886
野趣味
野趣味 2020-12-16 20:13
// JSON object to hold the information, which is sent to the server
JSONObject jsonObjSend = new JSONObject();
jsonObjSend.put(\"action\", \"myAction\");
jsonObjSend         


        
2条回答
  •  无人及你
    2020-12-16 20:42

    After seeing the example I understood that you are trying to do something similar as asked in Java JsonObject array value to key

    jsonObjSend.put("elementi", new JSONArray(new Object[] { "value1", "value2", "value3"} ));
    

    To simplify:

    JSONArray arr = new JSONArray();
    arr.put("value1");
    arr.put("value2");
    //...
    jsonObjSend.put("elementi", arr);
    

提交回复
热议问题