{ "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 } 将MQ消息 取出qualificationGroupId,organizationCode ,qualificationGroupName,partnerId 这四个对象的值 java代码实现
时间: 2023-07-03 17:27:33 浏览: 114
可以使用JSON库解析该JSON字符串,例如使用Jackson库。以下是示例代码:
```java
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
public class JsonParsingExample {
public static void main(String[] args) {
String jsonStr = "{ \"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 }";
try {
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(jsonStr);
String qualificationGroupId = jsonNode.get("orderPostParamDTO").get("param").get("qualificationGroupId").asText();
String organizationCode = jsonNode.get("orderPostParamDTO").get("param").get("organizationCode").asText();
String qualificationGroupName = jsonNode.get("orderPostParamDTO").get("param").get("qualificationGroupName").asText();
int partnerId = jsonNode.get("partnerId").asInt();
System.out.println("qualificationGroupId: " + qualificationGroupId);
System.out.println("organizationCode: " + organizationCode);
System.out.println("qualificationGroupName: " + qualificationGroupName);
System.out.println("partnerId: " + partnerId);
} catch (Exception e) {
e.printStackTrace();
}
}
}
```
输出结果为:
```
qualificationGroupId: 12345
organizationCode: 2222
qualificationGroupName: 22222
partnerId: 123
```
阅读全文