使用javaBean 创建JSon 打印String数组是出现"mojor":[{"bytes":[{},{},{},{},{},{}],"empty":false},{"bytes":[{},{},{},{},{},{},{},{},{}],"empty":false}]这样是什么原因?而用map等其他方法都是正常的,为什么?
private static void creatJsonByMap()
{
Map<String, Object> wangxiaoer = new HashMap<String, Object>();
wangxiaoer.put("name", "wangxiaoer");
wangxiaoer.put("has_girlfriend", false);
wangxiaoer.put("age", 25.2);
wangxiaoer.put("birthday", "1990-01-01");
wangxiaoer.put("school", "蓝翔");
wangxiaoer.put("major", new String[]{"理发","挖掘机"});
wangxiaoer.put("car", null);
wangxiaoer.put("house", null);
wangxiaoer.put("comment", "这是一个注释");
System.out.println(new JSONObject(wangxiaoer).toString());
}
public static void createJsonByBean(){
People wangxiaoer = new People();
wangxiaoer.setName("王小二");
wangxiaoer.setHas_girlfriend(false);
wangxiaoer.setAge(25.2);
wangxiaoer.setBirthday("1990-01-01");
wangxiaoer.setSchool("蓝翔");
wangxiaoer.setMojor(new String[]{ "理发" , "挖掘机"});
wangxiaoer.setHouse(null);
wangxiaoer.setComment("这是一个注释");
System.out.println(new JSONObject(wangxiaoer));
}