Android JSONObject : add Array to the put method

前端 未结 2 885
野趣味
野趣味 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:47

    JSONObject jsonBody = new JSONObject();
    jsonBody.put("action", "myAction"); //action is your string
    jsonBody.put("type", "elementi");
    JSONArray arr = new JSONArray();
    JSONObject elementi= new JSONObject();
    itemList.put("id", id);
    itemList.put("name", name);
    arr.put(elementi);
    jsonBody.put("elementi", arr);
    

提交回复
热议问题