How can I delete the nameValuePairs key from the JSONObject?

前端 未结 7 2031
陌清茗
陌清茗 2020-12-05 07:07

I\'m working on an Android project which needs a JSONObject for the body of my POST request. After putting the keys and values of the JSON I got the following line:

相关标签:
7条回答
  • 2020-12-05 08:07
        JSONObject jsonRequest = new JSONObject();
                        try {
                            jsonRequest.put("abc", "test");
                            jsonRequest.put("cba", "tye");
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
    
                        Log.d("jsonobject", "onClick: "+jsonRequest);
    
        (result: {"abc":"test","cba":"tye"})
    
        JsonParser jsonParser = new JsonParser();
        JsonObject jsonObject = (JsonObject)jsonParser.parse(jsonRequest.toString());
    
                    Log.d("jsonobjectparse", "onClick: "+jsonObject);
    
    (result: {"abc":"test","cba":"tye"})
    
    Once you are put the values into the jsonObject pass to the jsonParser it will solve the issue
    
    thats all. enjoy your coding.
    
    0 讨论(0)
提交回复
热议问题