急~~~~~~~~~~~~~~JSONArray转JSON的问题
JSONArray.fromObject(Object);后 如果Object中有一个Double类型的字段的值为null,
那么转后为json后null就转换为0了,这种情况该怎么解决呢?
求大神帮忙解决~ java json JsonArray
[解决办法]
json串中好像是不允许有空值的吧?
如果有空值自动转换为默认值吧?
public static void main(String[] args) {
ArrayList<Student> list=new ArrayList<Student>();
Student s1=new Student();
s1.setName("leilei");
s1.setAge(23);
Student s2=new Student();
s2.setName("leilei02");
//s2.setAge(23);
list.add(s1);
list.add(s2);
StringWriter str=new StringWriter();
ObjectMapper objectMapper=new ObjectMapper();
try {
objectMapper.writeValue(str, list);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(str);
}