• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

在构造JSONObject对象时,出现以下现象

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;
        }
}

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

全部参与2

我也遇到这个问题不知道怎么解决,楼主解决了吗??

使用道具 举报

String[] major = new String[]{"数学","物理"};改成String[] major = {"数学","物理"};

使用道具 举报

发新帖

发布任务需求已有1031167位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!