How to escape the quotes in JSON Object?

后端 未结 4 1499
予麋鹿
予麋鹿 2021-01-19 17:31

Below is my method which makes the JSONObject and then print out the JSONString.

I am using Google GSON.

private String gen         


        
4条回答
  •  灰色年华
    2021-01-19 18:27

    If you are using Android Platform 23 then you shall able to use org.json.JSONObject instead:

    private String generateData(ConcurrentMap>> dataTable, int i) {
    JSONObject jsonObject = new JSONObject();
    try {
        JSONArray apArray = new JSONArray();
        for (Integer i : ap) {
            apArray.put(i.intValue());
        }
        JSONArray bpArray = new JSONArray();
        for (Integer i : bp) {
            bpArray.put(i.intValue());
        }
    
        jsonObject.put("description", "test data");
    
        jsonObject.put("ap", apArray);
        jsonObject.put("bp", bpArray);
        Log.d("Json string", jsonObject.toString());
    }catch(JSONException e){
        Log.e("JSONException",e.getMessage());
    }
    
    System.out.println(jsonObject.toString());
    return jsonObject.toString();
    }
    

提交回复
热议问题