在json中new String[]出現了亂碼
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());
}
}
得出來的結果是這樣的
{"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; 用一個空對象put進去,話說你的編譯器不會提示不能直接put null嗎?下面這個代碼我本機輸出是沒有問題的,你試試看看
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());