美文网首页
JsonObject生成Json字符串有转意字符

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

作者: 程序员学园 | 来源:发表于2017-05-15 18:28 被阅读0次
"PatientInfo": {
        "Name": "{\"GivenName\":\"sduie\"}",
        "Height": "",
        "Weight": "身高170",
        "age": "",
        "Sex": -1,
         "PatientID": ""
    }

如上图

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

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

原因是

Paste_Image.png

换成

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字符串有转意字符

      本文链接:https://www.haomeiwen.com/subject/njghxxtx.html