wangxiaoer.put("major",new String[]{"烹饪","挖掘机"});得到的数据不完整,少了“]”
JSONObject wangxiaoer = new JSONObject();
try {
Object objnull = null;
wangxiaoer.put("name","王小二");
wangxiaoer.put("age", 25.2);
wangxiaoer.put("birthday","1994-01-02");
wangxiaoer.put("school", "蓝翔");
wangxiaoer.put("major",new String[]{"烹饪","挖掘机"});
wangxiaoer.put("has_girlfriend",false);
wangxiaoer.put("car", objnull);
wangxiaoer.put("house", objnull);
wangxiaoer.put("comment", "这是一个注释");
Log.i("info", "===="+wangxiaoer.toString());
System.out.println("===="+wangxiaoer.toString());
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
得到的结果:{"birthday":"1994-01-02","school":"蓝翔","comment":"这是一个注释","has_girlfriend":false,"major":"[Ljava.lang.String;@4a7c04c0","age":25.2,"name":"王小二"}
求解:为甚么少了一个"]",major就不能构成数组对象