{ "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 这三个对象的值 java代码实现
时间: 2023-07-03 16:27:32 浏览: 96
可以使用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();
System.out.println("qualificationGroupId: " + qualificationGroupId);
System.out.println("organizationCode: " + organizationCode);
System.out.println("qualificationGroupName: " + qualificationGroupName);
} catch (Exception e) {
e.printStackTrace();
}
}
}
```
输出结果为:
```
qualificationGroupId: 12345
organizationCode: 2222
qualificationGroupName: 22222
```
阅读全文