使用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值!