为什么我的输出结果只有一对花括号啊?
为什么我的输出结果只有一对花括号啊?
为什么我的输出结果只有一对花括号啊?
2017-04-19
import org.json.JSONObject;
public class JSONObjectSample {
public static void main(String[] args) {
createJsonByJavaBean();
}
private static void createJsonByJavaBean() {
PersonInfo info = new PersonInfo();
info.setName("John");
info.setSex("male");
info.setAge(22);
info.setStudent(true);
info.setHobbies(new String[] {"hiking", "swimming"});
JSONObject obj = new JSONObject(info);
System.out.println(obj);
}
class PersonInfo {
private String name;
private String sex;
private int age;
private boolean isStudent;
private String[] hobbies;
public void setName(String name) {
this.name = name;
}
public void setSex(String sex) {
this.sex = sex;
}
public void setAge(int age) {
this.age = age;
}
public void setStudent(boolean isStudent) {
this.isStudent = isStudent;
}
public void setHobbies(String[] hobbies) {
this.hobbies = hobbies;
}
}
}
举报