当json字符串与javabean不对称是
String str="{name:'zs',age:'aa',add:'cc',bir:'dd',aa:null,bb:null}"; MyJava myj=JSON.parseObject(str,MyJava.class); System.out.print(myj.getAdd());
public class MyJava { private String name; private String age; private String add; private String bir; }
1:用一般的json转换报错,因为字符串中的aa,bb在javabean中没有对应的
JSONObject.toBean(jsonObject, MyJava.class);
2:用fastjson没问题
JSON.parseObject(jsonObject.toString(), MyJava.class);