需求

android 如何使用 fastjson ?

解决

注意: fastjson 的版本号,有些版本不合适。

implementation 'com.alibaba:fastjson:1.1.76.android'

AliveBean.java

package com.tianze.coagulationanalyzer.network;

public class AliveBean {
    private String type;
    private String ip;
    private String sn;
    private String time;
    private String reagentId;

    public String getType() {
      return type;
    }

    public void setType(String type) {
      this.type = type;
    }

    public String getIp() {
      return ip;
    }

    public void setIp(String ip) {
      this.ip = ip;
    }

    public String getSn() {
      return sn;
    }

    public void setSn(String sn) {
      this.sn = sn;
    }

    public String getTime() {
      return time;
    }

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

    public String getReagentId() {
      return reagentId;
    }

    public void setReagentId(String reagentId) {
      this.reagentId = reagentId;
    }
}
String s;
AliveAckBean ack = JSON.parseObject(s, AliveAckBean.class);
if (ack.getType().equals(NetworkManage.DataType.kTypeAlive.value())) {
}

参考