JsonObject生成Json字符串有转意字符

"PatientInfo": {
        "Name": "{\"GivenName\":\"sduie\"}",
        "Height": "",
        "Weight": "身高170",
        "age": "",
        "Sex": -1,
         "PatientID": ""
    }

如上图

"Name": "{\"GivenName\":\"sduie\"}"

利用org.json.JSONObject生成Json字符串有转意字符

原因是

JsonObject生成Json字符串有转意字符_第1张图片
Paste_Image.png

换成

JsonObject生成Json字符串有转意字符_第2张图片
Paste_Image.png

···
private static JSONObject getObjectName(Name name) {
JSONObject nameObject = new JSONObject();
try {
nameObject.put("GivenName", name.getGivenName());

    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        System.out.println("===-BJ--nameObject===" + e);

    }
    System.out.println("===-BJ--nameObject===" + nameObject.toString());

    return nameObject;
}

···

就好了。

还有注意下,利用阿里巴巴的fastjson生成json字符串时,会自动将首字母大写的转为小写。

你可能感兴趣的:(JsonObject生成Json字符串有转意字符)