{ "updatorCode": "00013838", "updTm": 1694762024000, "checkTools": "OldApp" }此json转为java对象如何处理
时间: 2023-10-21 14:07:04 浏览: 73
可以使用Jackson库将该JSON字符串转换为Java对象。具体代码如下:
```
import com.fasterxml.jackson.databind.ObjectMapper;
public class JsonToObject {
public static void main(String[] args) throws Exception {
String json = "{\"updatorCode\": \"00013838\", \"updTm\": 1694762024000, \"checkTools\": \"OldApp\"}";
ObjectMapper objectMapper = new ObjectMapper();
MyObject myObject = objectMapper.readValue(json, MyObject.class);
System.out.println(myObject);
}
}
class MyObject {
private String updatorCode;
private long updTm;
private String checkTools;
public String getUpdatorCode() {
return updatorCode;
}
public void setUpdatorCode(String updatorCode) {
this.updatorCode = updatorCode;
}
public long getUpdTm() {
return updTm;
}
public void setUpdTm(long updTm) {
this.updTm = updTm;
}
public String getCheckTools() {
return checkTools;
}
public void setCheckTools(String checkTools) {
this.checkTools = checkTools;
}
@Override
public String toString() {
return "MyObject{" +
"updatorCode='" + updatorCode + '\'' +
", updTm=" + updTm +
", checkTools='" + checkTools + '\'' +
'}';
}
}
```
阅读全文