当前位置: 首页 > 知识库问答 >
问题:

用改型模型模式解析JSON

石喜
2023-03-14

错误是:

方法引发了'java.lang.NullPointerException'异常。无法计算pl.netizens.eonbeacon.storage.eonbeaconmodel.ToString()

{
  "data": {
    "list": [
      {
        "id": 58,
        "beacon_id": "58",
        "bridge_id": null,
        "mesh_id": null,
        "name": "eon_3c",
        "location": "abcdlk",
        "mac_address": "3c:cf:82:8a:e7:fe",
        "firmware": "2.1",
        "pcb_revision": "2.0",
        "battery_level": "99",
        "password": "0000",
        "ib": {
          "turn_on": "1",
          "major": "33",
          "minor": "344",
          "tx_power": "7",
          "interval": "400",
          "uuid": "dae19960-18ea-11e5-8ff0-0002a5d5c521",
          "secure_uuid": "0"
        },
        "euid": {
          "turn_on": "0",
          "namespace": null,
          "instance": null,
          "tx_power": null,
          "interval": null
        },
        "eeid": {
          "turn_on": "0",
          "tx_power": null,
          "interval": null
        },
        "eurl": {
          "turn_on": "0",
          "tx_power": null,
          "interval": null,
          "url": null
        },
        "etlm": {
          "turn_on": "0",
          "tx_power": null,
          "interval": null
        },
        "assigned_bridge_id": null
      },
      {
        "id": 56,
        "beacon_id": "56",
        "bridge_id": null,
        "mesh_id": null,
        "name": "Eon_e6",
        "location": "test",
        "mac_address": "e6:f5:8a:94:b8:c7",
        "firmware": "2.1",
        "pcb_revision": "2.0",
        "battery_level": null,
        "password": "0000",
        "ib": {
          "turn_on": "1",
          "major": "2591",
          "minor": "0",
          "tx_power": "10",
          "interval": "2593",
          "uuid": "dae19960-18ea-11e5-8ff0-0002a5d5c521",
          "secure_uuid": "0"
        },
        "euid": {
          "turn_on": "0",
          "namespace": null,
          "instance": null,
          "tx_power": null,
          "interval": null
        },
        "eeid": {
          "turn_on": "0",
          "tx_power": null,
          "interval": null
        },
        "eurl": {
          "turn_on": "0",
          "tx_power": null,
          "interval": null,
          "url": null
        },
        "etlm": {
          "turn_on": "0",
          "tx_power": null,
          "interval": null
        },
        "assigned_bridge_id": null
      },
      {
        "id": 57,
        "beacon_id": "57",
        "bridge_id": "13",
        "mesh_id": "278",
        "name": "Marta B",
        "location": "lk",
        "mac_address": "e1:4b:64:c3:80:e2",
        "firmware": "2.1",
        "pcb_revision": "2.0",
        "battery_level": "97",
        "password": "0000",
        "ib": {
          "turn_on": "1",
          "major": "325",
          "minor": "10",
          "tx_power": "8",
          "interval": "610",
          "uuid": "dae19960-18ea-11e5-8ff0-0002a5d5c521",
          "secure_uuid": "0"
        },
        "euid": {
          "turn_on": "0",
          "namespace": null,
          "instance": null,
          "tx_power": null,
          "interval": null
        },
        "eeid": {
          "turn_on": "0",
          "tx_power": null,
          "interval": null
        },
        "eurl": {
          "turn_on": "0",
          "tx_power": null,
          "interval": null,
          "url": null
        },
        "etlm": {
          "turn_on": "0",
          "tx_power": null,
          "interval": null
        },
        "assigned_bridge_id": null
      }
    ]
  },
  "ver": 1,
  "time": 1475671202,
  "status": 1,
  "status_msg": ""
}
public class BasicResponse<T> {
    @Expose
    public T data;
    @Expose
    public int ver;
    @Expose
    public long time;
    @Expose
    public byte status;
    @Expose
    public String status_msg;
}
public class BeaconResponse {
    @Expose
    public int id;
    @Expose
    public long beacon_id;
    @Expose
    public long bridge_id;
    @Expose
    public long mesh_id;
    @Expose
    public String name;
    @Expose
    public String location;
    @Expose
    public String mac_address;
    @Expose
    public String firmware;
    @Expose
    public String pcb_revision;
    @Expose
    public byte battery_level;
    @Expose
    public String password;
    @Expose
    @SerializedName("ib")
    public Ib ib;
    @Expose
    @SerializedName("euid")
    public Euid euid;
    @SerializedName("eeid")
    @Expose
    public Eeid eeid;
    @SerializedName("eurl")
    @Expose
    public Eurl eurl;
    @SerializedName("etlm")
    @Expose
    public Etlm etlm;
    @Expose
    public int assigned_bridge_id;
@Subscribe
    public void getUserBeacons(GetBeaconsListCommand command) {
        Callback<BasicResponse<BeaconsListResponse>> callback = new Callback<BasicResponse<BeaconsListResponse>>() {
            @Override
            public void success(BasicResponse<BeaconsListResponse> basicResponse, Response response) {
                if (ResponseStatus.SUCCESS.statusCode == basicResponse.status)
                    EventBus.post(new BeaconsListFetchedEvent(basicResponse.data));
                else
                    EventBus.post(new NetworkFailureEvent(ResponseStatus.getByStatus(basicResponse.status), basicResponse.status_msg));
            }

            @Override
            public void failure(RetrofitError error) {
            }
        };
        service.beaconsList(callback);
    }

Eeid,Eeid模型:

public class EuidModel extends Model {

    @Expose
    public boolean  turn_on;
    @Expose
    public  String namespace;
    @Expose
    public String  instance;
    @Expose
    public  int tx_power;
    @Expose
    public long  interval;

    public boolean isTurn_on() {
        return turn_on;
    }

    public void setTurn_on(boolean turn_on) {
        this.turn_on = turn_on;
    }

    public String getNamespace() {
        return namespace;
    }

    public void setNamespace(String namespace) {
        this.namespace = namespace;
    }

    public String getInstance() {
        return instance;
    }

    public void setInstance(String instance) {
        this.instance = instance;
    }

    public int getTx_power() {
        return tx_power;
    }

    public void setTx_power(int tx_power) {
        this.tx_power = tx_power;
    }

    public long getInterval() {
        return interval;
    }

    public void setInterval(long interval) {
        this.interval = interval;
    }


    private Map<String, Object> additionalProperties = new HashMap<String, Object>();

    public Map<String, Object> getAdditionalProperties() {
        return this.additionalProperties;
    }

    public void setAdditionalProperty(String name, Object value) {
        this.additionalProperties.put(name, value);
    }
public class EeidModel extends Model {

    @Column
    public boolean turn_on;
    @Column
    public int tx_power;
    @Column
    public int interval;
    private Map<String, Object> additionalProperties = new HashMap<String, Object>();

    public Map<String, Object> getAdditionalProperties() {
        return this.additionalProperties;
    }

    public void setAdditionalProperty(String name, Object value) {
        this.additionalProperties.put(name, value);
    }

共有1个答案

束福
2023-03-14

试试这个模式,我相信它会很好地工作:-

public class model {

    private DataBean data;

    private int ver;
    private int time;
    private int status;
    private String status_msg;

    public DataBean getData() {
        return data;
    }

    public void setData(DataBean data) {
        this.data = data;
    }

    public int getVer() {
        return ver;
    }

    public void setVer(int ver) {
        this.ver = ver;
    }

    public int getTime() {
        return time;
    }

    public void setTime(int time) {
        this.time = time;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getStatus_msg() {
        return status_msg;
    }

    public void setStatus_msg(String status_msg) {
        this.status_msg = status_msg;
    }

    private static class DataBean {

        private List<ListBean> list;

        public List<ListBean> getList() {
            return list;
        }

        public void setList(List<ListBean> list) {
            this.list = list;
        }

        static class ListBean {
            private int id;
            private String beacon_id;
            private Object bridge_id;
            private Object mesh_id;
            private String name;
            private String location;
            private String mac_address;
            private String firmware;
            private String pcb_revision;
            private String battery_level;
            private String password;

            private IbBean ib;

            private EuidBean euid;

            private EeidBean eeid;

            private EurlBean eurl;

            private EtlmBean etlm;
            private Object assigned_bridge_id;

            public int getId() {
                return id;
            }

            public void setId(int id) {
                this.id = id;
            }

            public String getBeacon_id() {
                return beacon_id;
            }

            public void setBeacon_id(String beacon_id) {
                this.beacon_id = beacon_id;
            }

            public Object getBridge_id() {
                return bridge_id;
            }

            public void setBridge_id(Object bridge_id) {
                this.bridge_id = bridge_id;
            }

            public Object getMesh_id() {
                return mesh_id;
            }

            public void setMesh_id(Object mesh_id) {
                this.mesh_id = mesh_id;
            }

            public String getName() {
                return name;
            }

            public void setName(String name) {
                this.name = name;
            }

            public String getLocation() {
                return location;
            }

            public void setLocation(String location) {
                this.location = location;
            }

            public String getMac_address() {
                return mac_address;
            }

            public void setMac_address(String mac_address) {
                this.mac_address = mac_address;
            }

            public String getFirmware() {
                return firmware;
            }

            public void setFirmware(String firmware) {
                this.firmware = firmware;
            }

            public String getPcb_revision() {
                return pcb_revision;
            }

            public void setPcb_revision(String pcb_revision) {
                this.pcb_revision = pcb_revision;
            }

            public String getBattery_level() {
                return battery_level;
            }

            public void setBattery_level(String battery_level) {
                this.battery_level = battery_level;
            }

            public String getPassword() {
                return password;
            }

            public void setPassword(String password) {
                this.password = password;
            }

            public IbBean getIb() {
                return ib;
            }

            public void setIb(IbBean ib) {
                this.ib = ib;
            }

            public EuidBean getEuid() {
                return euid;
            }

            public void setEuid(EuidBean euid) {
                this.euid = euid;
            }

            public EeidBean getEeid() {
                return eeid;
            }

            public void setEeid(EeidBean eeid) {
                this.eeid = eeid;
            }

            public EurlBean getEurl() {
                return eurl;
            }

            public void setEurl(EurlBean eurl) {
                this.eurl = eurl;
            }

            public EtlmBean getEtlm() {
                return etlm;
            }

            public void setEtlm(EtlmBean etlm) {
                this.etlm = etlm;
            }

            public Object getAssigned_bridge_id() {
                return assigned_bridge_id;
            }

            public void setAssigned_bridge_id(Object assigned_bridge_id) {
                this.assigned_bridge_id = assigned_bridge_id;
            }

            static class IbBean {
                private String turn_on;
                private String major;
                private String minor;
                private String tx_power;
                private String interval;
                private String uuid;
                private String secure_uuid;

                public String getTurn_on() {
                    return turn_on;
                }

                public void setTurn_on(String turn_on) {
                    this.turn_on = turn_on;
                }

                public String getMajor() {
                    return major;
                }

                public void setMajor(String major) {
                    this.major = major;
                }

                public String getMinor() {
                    return minor;
                }

                public void setMinor(String minor) {
                    this.minor = minor;
                }

                public String getTx_power() {
                    return tx_power;
                }

                public void setTx_power(String tx_power) {
                    this.tx_power = tx_power;
                }

                public String getInterval() {
                    return interval;
                }

                public void setInterval(String interval) {
                    this.interval = interval;
                }

                public String getUuid() {
                    return uuid;
                }

                public void setUuid(String uuid) {
                    this.uuid = uuid;
                }

                public String getSecure_uuid() {
                    return secure_uuid;
                }

                public void setSecure_uuid(String secure_uuid) {
                    this.secure_uuid = secure_uuid;
                }
            }

            static class EuidBean {
                private String turn_on;
                private Object namespace;
                private Object instance;
                private Object tx_power;
                private Object interval;

                public String getTurn_on() {
                    return turn_on;
                }

                public void setTurn_on(String turn_on) {
                    this.turn_on = turn_on;
                }

                public Object getNamespace() {
                    return namespace;
                }

                public void setNamespace(Object namespace) {
                    this.namespace = namespace;
                }

                public Object getInstance() {
                    return instance;
                }

                public void setInstance(Object instance) {
                    this.instance = instance;
                }

                public Object getTx_power() {
                    return tx_power;
                }

                public void setTx_power(Object tx_power) {
                    this.tx_power = tx_power;
                }

                public Object getInterval() {
                    return interval;
                }

                public void setInterval(Object interval) {
                    this.interval = interval;
                }
            }

            static class EeidBean {
                private String turn_on;
                private Object tx_power;
                private Object interval;

                public String getTurn_on() {
                    return turn_on;
                }

                public void setTurn_on(String turn_on) {
                    this.turn_on = turn_on;
                }

                public Object getTx_power() {
                    return tx_power;
                }

                public void setTx_power(Object tx_power) {
                    this.tx_power = tx_power;
                }

                public Object getInterval() {
                    return interval;
                }

                public void setInterval(Object interval) {
                    this.interval = interval;
                }
            }

            static class EurlBean {
                private String turn_on;
                private Object tx_power;
                private Object interval;
                private Object url;

                public String getTurn_on() {
                    return turn_on;
                }

                public void setTurn_on(String turn_on) {
                    this.turn_on = turn_on;
                }

                public Object getTx_power() {
                    return tx_power;
                }

                public void setTx_power(Object tx_power) {
                    this.tx_power = tx_power;
                }

                public Object getInterval() {
                    return interval;
                }

                public void setInterval(Object interval) {
                    this.interval = interval;
                }

                public Object getUrl() {
                    return url;
                }

                public void setUrl(Object url) {
                    this.url = url;
                }
            }

            static class EtlmBean {
                private String turn_on;
                private Object tx_power;
                private Object interval;

                public String getTurn_on() {
                    return turn_on;
                }

                public void setTurn_on(String turn_on) {
                    this.turn_on = turn_on;
                }

                public Object getTx_power() {
                    return tx_power;
                }

                public void setTx_power(Object tx_power) {
                    this.tx_power = tx_power;
                }

                public Object getInterval() {
                    return interval;
                }

                public void setInterval(Object interval) {
                    this.interval = interval;
                }
            }
        }
    }
}
 类似资料:
  • 我试图寻找此错误的解决方案,但仍然无法使用类,因此我尝试手动进行导入,但只能看到三个类、和。 在中查看时,我可以看到文件,在打开JAR时,我还可以看到类pattern.class。 有人能帮助Eclipse为什么看不到这个类吗?

  • 在程序集的schemaLanguage后面是“http://www.w3.org/xml/xmlschema/v1.1”,newSchema()返回类型为{org.apache.xerces.jaxp.validation.simplexmlschema}的模式。我无法导入该类,错误是-org.apache.xerces.jaxp.validation.SimpleXMLSchema类型不可见 任

  • 本文向大家介绍生成式模型、判别式模型相关面试题,主要包含被问及生成式模型、判别式模型时的应答技巧和注意事项,需要的朋友参考一下 https://github.com/imhuay/Algorithm_Interview_Notes-Chinese/blob/master/A-机器学习/A-机器学习基础.md#生成模型与判别模型 生成式模型(generative model)会对x和y的联合分布p(

  • 本文向大家介绍详解JAVA 原型模式,包括了详解JAVA 原型模式的使用技巧和注意事项,需要的朋友参考一下 原型模式 原型模式(Prototype Pattern)是用于创建重复的对象,同时又能保证性能。这种类型的设计模式属于创建型模式,它提供了一种创建对象的最佳方式。 这种模式是实现了一个原型接口,该接口用于创建当前对象的克隆。当直接创建对象的代价比较大时,则采用这种模式。例如,一个对象需要在一

  • 主要内容:介绍,实现,Shape.java,Rectangle.java,Square.java,Circle.java,ShapeCache.java,PrototypePatternDemo.java原型模式(Prototype Pattern)是用于创建重复的对象,同时又能保证性能。这种类型的设计模式属于创建型模式,它提供了一种创建对象的最佳方式之一。 这种模式是实现了一个原型接口,该接口用于创建当前对象的克隆。当直接创建对象的代价比较大时,则采用这种模式。例如,一个对象需要在一个高代价的

  • 亦称: 克隆、Clone、Prototype 意图 原型模式是一种创建型设计模式, 使你能够复制已有对象, 而又无需使代码依赖它们所属的类。 问题 如果你有一个对象, 并希望生成与其完全相同的一个复制品, 你该如何实现呢? 首先, 你必须新建一个属于相同类的对象。 然后, 你必须遍历原始对象的所有成员变量, 并将成员变量值复制到新对象中。 不错! 但有个小问题。 并非所有对象都能通过这种方式进行复