net.sf.json.JSONObject在参数为空时,返回json中没有这个key

来源:互联网 发布:贪心算法最短路径问题 编辑:程序博客网 时间:2024/06/06 03:00

使用net.sf.json.JSONObject

实例:
Person person = new Person();
person.setAge(14);
person.setSex(“Female”);
person.setAddress(“”);
person.setName(“小戏”);

JSONObject tempJson = new JSONObject();
tempJson.put(“name”,person.getName() );
tempJson.put(“age”, person.getAge());
tempJson.put(“address”, person.getAdress());

System.out.println(tempJson.toString());

{“name”:”张云凤”,”age”:14}

在参数为空时,返回的string中没有address值!

阅读全文
0 0
原创粉丝点击