在json中new String[]出現(xiàn)了亂碼
private static void JSONObject() {
// TODO Auto-generated method stub
JSONObject wangxiaoer = new JSONObject();
wangxiaoer.put("name", "王小二");
wangxiaoer.put("age", 25.2);
wangxiaoer.put("birthday", "1990-01-01");
wangxiaoer.put("major" ,new String[]{"1","2"});
wangxiaoer.put("car",null);
wangxiaoer.put("house",null);
System.out.println(wangxiaoer.toString());
}
}
得出來(lái)的結(jié)果是這樣的
{"car":null,"birthday":"1990-01-01","age":25.2,"name":"王小二","house":null,"major":[Ljava.lang.String;@b166b5}
2017-10-09
這就比較奇怪了,同樣的代碼,只是我wangxiaoer.put("house",null);這樣直接put null的代碼改為了Object nullObj = null; 用一個(gè)空對(duì)象put進(jìn)去,話(huà)說(shuō)你的編譯器不會(huì)提示不能直接put null嗎?下面這個(gè)代碼我本機(jī)輸出是沒(méi)有問(wèn)題的,你試試看看
Object nullObj = null;
JSONObject wangxiaoer = new JSONObject();
wangxiaoer.put("name", "王小二");
wangxiaoer.put("age", 25.2);
wangxiaoer.put("birthday", "1990-01-01");
wangxiaoer.put("major" ,new String[]{"1","2"});
wangxiaoer.put("car",nullObj);
wangxiaoer.put("house",nullObj);
System.out.println(wangxiaoer.toString());