简体   繁体   English

JSONObject.element()方法将“ null”字符串值转换为null

[英]JSONObject.element() method converts “null” string value to null

When I try to put "null" string value to a JSONObject using the API JSONObject.element(key, value) , this API converts this "null" string value to null . 当我尝试把"null"的字符串值,一个JSONObject使用API JSONObject.element(key, value) ,这个API将这个"null"字符串值null

API used: net.sf.json.JSONObject, JAR version: json-lib-2.3-jdk15 使用的API:net.sf.json.JSONObject,JAR版本:json-lib-2.3-jdk15

JSONObject jObj = new JSONObject();
jObj.element("msg", null);

For the given code snippet, the output is 对于给定的代码段,输出为

{"msg":null}

However, it should be 但是,应该

{"msg":"null"}

Never mind, I have handled this at the UI side. 没关系,我已经在UI端处理过了。 The JSONObject API doesn't support the requirement. JSONObject API不支持该要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM