我试图使用谷歌凌空发布JSON但我发现错误,同时传递List <sting>形式

时间:2017-12-10 08:44:02

标签: android json post arraylist android-volley

{      &#34; UserName&#34;:&#34; abcd&#34;,      &#34;密码&#34;:&#34; hjhdfg&#34;,      &#34; int1&#34;:1,      &#34; mydate&#34;:&#34; 2017-12-12T00:00:00&#34;,      &#34; mydecimal&#34;:2.3,      &#34; id&#34;:&#34; 00000000-0000-0000-0000-000000000000&#34;,      &#34;列出PODetails&#34;:[        {            &#34;姓名&#34;:&#34; mohit&#34;,            &#34; Id&#34;:1        }      ]     }

{ RequestQueue requestQueue = Volley.newRequestQueue(this);
    //this is the code to write
    JSONObject mRequestBody = new JSONObject();
    try {

        poDetails = new ArrayList<>();
        mRequestBody.put("UserName", "abhishek");
        mRequestBody.put("Password", "dvjndsjs");
        mRequestBody.put("int1", 1);
        mRequestBody.put("mydate", date_time.dateFormatter);
        mRequestBody.put("mydecimal", 0.0);
        mRequestBody.put("id", idOne);
        List<String> PODetails = (List<String>) 
        mRequestBody.getJSONArray("PODetails");
  

块引用               Log.e(&#34; POdetails&#34;,PODetails.toString());}

1 个答案:

答案 0 :(得分:0)

{
    "UserName": "abcd",
    "Password": "hjhdfg",
    "int1": 1,
    "mydate": "2017-12-12T00:00:00",
    "mydecimal": 2.3,
    "id": "00000000-0000-0000-0000-000000000000",
    "List PODetails": [{
        "Name": "mohit",
        "Id": 1
    }]
}

根据你的JSON,你需要这样做。

     try {
            JSONObject mRequestBody = new JSONObject();
            mRequestBody.put("UserName", "abhishek");
            mRequestBody.put("Password", "dvjndsjs");
            mRequestBody.put("int1", 1);
            mRequestBody.put("mydate", date_time.dateFormatter);
            mRequestBody.put("id", idOne);
            mRequestBody.put("mydecimal", 0.0);
            JSONArray podDetailsArray = new JSONArray();
            podDetailsArray.put(new JSONObject().put("Name", "mohit").put("Id",1));
        } catch (JSONException e) {
            e.printStackTrace();
        }