亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在構造JSONObject對象時,出現以下現象

在構造JSONObject對象時,出現以下現象

晨貓 2016-09-04 21:27:54
public static void main(String[] args) throws JSONException { Persion persion = new Persion(); persion.setName("小明"); persion.setAge(23); String[] major = new String[]{"數學","物理"}; persion.setMajor(major); persion.setHas_girlfriend(true); House house = new House("15#204","xx家園",1000000); persion.setHouse(house); persion.setBirthday("1993-04-05"); JSONObject jsonObject = new JSONObject(persion); System.out.println(jsonObject); }結果:{"birthday":"1993-04-05","major":[{"bytes":[{},{},{},{},{},{}],"empty":false},{"bytes":[{},{},{},{},{},{}],"empty":false}],"name":"小明","has_girlfriend":true,"ignore":null,"house":{"price":1000000,"name":"xx家園","id":"15#204"},"age":23}補充:public class Persion { private String name; private int age; private String[] major; private boolean has_girlfriend; private String birthday; private Object house; private transient String ignore; public String getIgnore() { return ignore; } public void setIgnore(String ignore) { this.ignore = ignore; } public String getBirthday() { return birthday; } public void setBirthday(String birthday) { this.birthday = birthday; } public Object getHouse() { return house; } public void setHouse(Object house) { this.house = house; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String[] getMajor() { return major; } public void setMajor(String[] major) { this.major = major; } public boolean isHas_girlfriend() { return has_girlfriend; } public void setHas_girlfriend(boolean has_girlfriend) { this.has_girlfriend = has_girlfriend; } @Override public String toString() { return "Persion [name=" + name + ", age=" + age + ", major=" + Arrays.toString(major) + ", has_girlfriend=" + has_girlfriend + ", birthday=" + birthday + ", house=" + house + "]"; }}public class House { private String id; private String name; private float price; public House() { super(); } public House(String id, String name, float price) { super(); this.id = id; this.name = name; this.price = price; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public float getPrice() { return price; } public void setPrice(float price) { this.price = price; }}
查看完整描述

4 回答

?
楓葉梨花

TA貢獻1條經驗 獲得超0個贊

我也遇到這個問題不知道怎么解決,樓主解決了嗎??

查看完整回答
反對 回復 2017-03-29
  • 楓葉梨花
    楓葉梨花
    還是不行哎!完全復制你的程序也不行??!不知道為什么
  • 晨貓
    晨貓
    那就不要用字符串數組了,用集合
?
摩訶迦葉

TA貢獻146條經驗 獲得超54個贊

String[] major = new String[]{"數學","物理"};改成String[] major = {"數學","物理"};

查看完整回答
反對 回復 2016-09-04
  • 晨貓
    晨貓
    不行,結果一樣。
  • 摩訶迦葉
    摩訶迦葉
    你確定Persion類里的major是String[]類型么?,你把代碼貼上來看看
  • 晨貓
    晨貓
    已補充,謝謝您不厭其煩的回復,謝謝。
點擊展開后面1
  • 4 回答
  • 0 關注
  • 2605 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號