{"AliyunUid":1254135733563893,"CustId":100000006132001,"PartnerId":110000009054001,"PipCode":"dysms"} 将MQ消息 取出这四个对象的值 java代码实现
时间: 2023-07-03 09:27:40 浏览: 93
可以使用Java中的JSONObject来解析JSON字符串,并通过getXXX()系列方法获取对应的值,示例如下:
```java
import org.json.JSONObject;
public class MQMessage {
public static void main(String[] args) {
String jsonStr = "{\"AliyunUid\":1254135733563893,\"CustId\":100000006132001,\"PartnerId\":110000009054001,\"PipCode\":\"dysms\"}";
JSONObject json = new JSONObject(jsonStr);
// 获取AliyunUid的值
long aliyunUid = json.getLong("AliyunUid");
System.out.println("AliyunUid: " + aliyunUid);
// 获取CustId的值
long custId = json.getLong("CustId");
System.out.println("CustId: " + custId);
// 获取PartnerId的值
long partnerId = json.getLong("PartnerId");
System.out.println("PartnerId: " + partnerId);
// 获取PipCode的值
String pipCode = json.getString("PipCode");
System.out.println("PipCode: " + pipCode);
}
}
```
输出结果为:
```
AliyunUid: 1254135733563893
CustId: 100000006132001
PartnerId: 110000009054001
PipCode: dysms
```
阅读全文