Я хочу разобрать строку json в JSONObject, но символ ":", кажется, анализирует ошибку
Например -> "time": "2019-05-28T16:30:29Z"
будет неправильно
Но изменилось на "time": "20190526"
ОК
Это весь объект json:
{
"channel": 922875000,
"sf": 12,
"time": "2019-05-28T16:30:29Z",
"gwip": "192.168.0.180",
"gwid": "00001c497b431ff5",
"repeater": "00000000ffffffff",
"systype": 170,
"rssi": -103,
"snr": 20.5,
"snr_max": 33,
"snr_min": 18,
"macAddr": "00000000aabb60ba",
"data": "00000000",
"frameCnt": 8,
"fport": 3
}
и код разбора:
try {
JSONObject sensorObject = new JSONObject(message.toString());
SensorModel sensorModel = new Gson().fromJson(sensorObject.toString(), SensorModel.class);
} catch (JSONException e) {
logger.error(e.getMessage());
}
Как я могу позволить ему сохранить тот же "2019:05:26"
контент?
SensorModel:
@Entity
public class SensorModel {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@NotNull
private long channel;
@NotNull
private int sf;
@NotNull
private String time;
@NotNull
private String gwip;
@NotNull
private String gwid;
private String repeater;
private int systype;
private double rssi;
private double snr;
private double snr_max;
private double snr_min;
private String macAddr;
private String data;
private int frameCnt;
private int fport;
public void setId(long id) {
this.id = id;
}
public void setChannel(long channel) {
this.channel = channel;
}
public void setSf(int sf) {
this.sf = sf;
}
public void setTime(String time) {
this.time = time;
}
public void setGwip(String gwip) {
this.gwip = gwip;
}
public void setGwid(String gwid) {
this.gwid = gwid;
}
public void setRepeater(String repeater) {
this.repeater = repeater;
}
public void setSystype(int systype) {
this.systype = systype;
}
public void setRssi(double rssi) {
this.rssi = rssi;
}
public void setSnr(double snr) {
this.snr = snr;
}
public void setSnr_max(double snr_max) {
this.snr_max = snr_max;
}
public void setSnr_min(double snr_min) {
this.snr_min = snr_min;
}
public void setMacAddr(String macAddr) {
this.macAddr = macAddr;
}
public void setData(String data) {
this.data = data;
}
public void setFrameCnt(int frameCnt) {
this.frameCnt = frameCnt;
}
public void setFport(int fport) {
this.fport = fport;
}
public long getId() {
return id;
}
public long getChannel() {
return channel;
}
public int getSf() {
return sf;
}
public String getTime() {
return time;
}
public String getGwip() {
return gwip;
}
public String getGwid() {
return gwid;
}
public String getRepeater() {
return repeater;
}
public int getSystype() {
return systype;
}
public double getRssi() {
return rssi;
}
public double getSnr() {
return snr;
}
public double getSnr_max() {
return snr_max;
}
public double getSnr_min() {
return snr_min;
}
public String getMacAddr() {
return macAddr;
}
public String getData() {
return data;
}
public int getFrameCnt() {
return frameCnt;
}
public int getFport() {
return fport;
}
}