{ "tenant": 1, "action": "AuditPass", "ordId": 1, "bizType": "sms", "partnerId": 123, "ordRemark": "备注信息", "curAuditor": "", "auditTemplateCode": "", "currentNum": 0, "allNum": 1, "auditDetail": "", "orderPostParamDTO": { "param": { "qualificationGroupId":"12345", "organizationCode":"2222", "qualificationGroupName":"22222" }, "auditRemark": "", "exceptionOrder": }, "orderCreateTime": 1230 } 将改消息解析成对象 java代码实现
时间: 2023-07-03 12:27:31 浏览: 97
在 Java 中,可以使用 JSON 解析库来将该 JSON 数据解析成对象。以下是使用 Jackson 库的示例代码:
```java
import com.fasterxml.jackson.databind.ObjectMapper;
public class JsonParser {
public static void main(String[] args) throws Exception {
String json = "{ \"tenant\": 1, \"action\": \"AuditPass\", \"ordId\": 1, \"bizType\": \"sms\", \"partnerId\": 123, \"ordRemark\": \"备注信息\", \"curAuditor\": \"\", \"auditTemplateCode\": \"\", \"currentNum\": 0, \"allNum\": 1, \"auditDetail\": \"\", \"orderPostParamDTO\": { \"param\": { \"qualificationGroupId\":\"12345\", \"organizationCode\":\"2222\", \"qualificationGroupName\":\"22222\" }, \"auditRemark\": \"\", \"exceptionOrder\": }, \"orderCreateTime\": 1230 }";
ObjectMapper mapper = new ObjectMapper();
Order order = mapper.readValue(json, Order.class);
System.out.println(order);
}
}
class Order {
private int tenant;
private String action;
private int ordId;
private String bizType;
private int partnerId;
private String ordRemark;
private String curAuditor;
private String auditTemplateCode;
private int currentNum;
private int allNum;
private String auditDetail;
private OrderPostParamDTO orderPostParamDTO;
private int orderCreateTime;
// getters and setters
// ...
@Override
public String toString() {
return "Order{" +
"tenant=" + tenant +
", action='" + action + '\'' +
", ordId=" + ordId +
", bizType='" + bizType + '\'' +
", partnerId=" + partnerId +
", ordRemark='" + ordRemark + '\'' +
", curAuditor='" + curAuditor + '\'' +
", auditTemplateCode='" + auditTemplateCode + '\'' +
", currentNum=" + currentNum +
", allNum=" + allNum +
", auditDetail='" + auditDetail + '\'' +
", orderPostParamDTO=" + orderPostParamDTO +
", orderCreateTime=" + orderCreateTime +
'}';
}
}
class OrderPostParamDTO {
private Param param;
private String auditRemark;
private String exceptionOrder;
// getters and setters
// ...
@Override
public String toString() {
return "OrderPostParamDTO{" +
"param=" + param +
", auditRemark='" + auditRemark + '\'' +
", exceptionOrder='" + exceptionOrder + '\'' +
'}';
}
}
class Param {
private String qualificationGroupId;
private String organizationCode;
private String qualificationGroupName;
// getters and setters
// ...
@Override
public String toString() {
return "Param{" +
"qualificationGroupId='" + qualificationGroupId + '\'' +
", organizationCode='" + organizationCode + '\'' +
", qualificationGroupName='" + qualificationGroupName + '\'' +
'}';
}
}
```
运行以上代码可以将该 JSON 数据解析成 Java 对象,并将其打印出来。你也可以使用其他 JSON 解析库来解析该数据。
阅读全文