第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

使用javaBean 創(chuàng)建JSon 打印String數(shù)組是出現(xiàn)"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[]{"理發(fā)","挖掘機"});

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[]{ "理發(fā)" , "挖掘機"});

wangxiaoer.setHouse(null);

wangxiaoer.setComment("這是一個注釋");

System.out.println(new JSONObject(wangxiaoer));

}


正在回答

2 回答

出現(xiàn)這個錯誤的原因是因為引入的json jar包太老了

? ? ? ?<dependency>

? ? ? <groupId>org.json</groupId>

? ? ? <artifactId>json</artifactId>

? ? ? <version>20160810</version>

? ? </dependency>

如圖,把pom.xml文件中的引用改成我上面這個就行了,也就會把原來的?<version>20090211</version>

改成<version>20160810</version>

,解決了就記得采納哦

3 回復(fù) 有任何疑惑可以回復(fù)我~
#1

Lee1227

感謝,我今天把依賴改了也成功了。之前一直都納悶為什么會這樣。
2019-08-11 回復(fù) 有任何疑惑可以回復(fù)我~

package mabentest.test;


import java.util.Arrays;


//java Bean 構(gòu)建Json

public class People {

private String name;

private String[] major;

private boolean has_girlfriend;

private double age;

private Object house;

private String birthday;

private String comment;

private String school;

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

/**

* @return major

*/

public String[] getMojor() {

return major;

}

/**

* @param mojor 要設(shè)置的 mojor

*/

public void setMojor(String[] major) {

this.major = major;

}

/**

* @return has_girlfriend

*/

public boolean isHas_girlfriend() {

return has_girlfriend;

}

/**

* @param has_girlfriend 要設(shè)置的 has_girlfriend

*/

public void setHas_girlfriend(boolean has_girlfriend) {

this.has_girlfriend = has_girlfriend;

}

/**

* @return age

*/

public double getAge() {

return age;

}

/**

* @param age 要設(shè)置的 age

*/

public void setAge(double age) {

this.age = age;

}

/**

* @return house

*/

public Object getHouse() {

return house;

}

/**

* @param house 要設(shè)置的 house

*/

public void setHouse(Object house) {

this.house = house;

}

/**

* @return birthday

*/

public String getBirthday() {

return birthday;

}

/**

* @param birthday 要設(shè)置的 birthday

*/

public void setBirthday(String birthday) {

this.birthday = birthday;

}

/**

* @return comment

*/

public String getComment() {

return comment;

}

/**

* @param comment 要設(shè)置的 comment

*/

public void setComment(String comment) {

this.comment = comment;

}

/* (非 Javadoc)

* @see java.lang.Object#toString()

*/

public String getSchool() {

return school;

}

public void setSchool(String school) {

this.school = school;

}

/* (非 Javadoc)

* @see java.lang.Object#toString()

*/

@Override

public String toString() {

return "People [name=" + name + ", major=" + Arrays.toString(major) + ", has_girlfriend=" + has_girlfriend

+ ", age=" + age + ", house=" + house + ", birthday=" + birthday + ", comment=" + comment + ", school="

+ school + "]";

}

}



0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消

使用javaBean 創(chuàng)建JSon 打印String數(shù)組是出現(xiàn)"mojor":[{"bytes":[{},{},{},{},{},{}],"empty":false},{"bytes":[{},{},{},{},{},{},{},{},{}],"empty":false}]這樣是什么原因?而用map等其他方法都是正常的,為什么?

我要回答 關(guān)注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號