message:{"msgHeader":{"ID":"INTYQ:INT_KFB:YC","T":"2023-11-20 14:32:49.586","VT":"realvalue"},使用java解析以上json数据
时间: 2023-11-21 08:58:56 浏览: 67
使用java来解析json
以下是使用Java解析JSON数据的示例代码:
```java
import org.json.JSONObject;
public class JsonParser {
public static void main(String[] args) {
String jsonStr = "{\"msgHeader\":{\"ID\":\"INTYQ:INT_KFB:YC\",\"T\":\"2023-11-20 14:32:49.586\",\"VT\":\"realvalue\"}}";
JSONObject jsonObj = new JSONObject(jsonStr); JSONObject msgHeaderObj = jsonObj.getJSONObject("msgHeader"); String id = msgHeaderObj.getString("ID");
String t = msgHeaderObj.getString("T");
String vt = msgHeaderObj.getString("VT"); System.out.println("ID: " + id);
System.out.println("T: " + t);
System.out.println("VT: " + vt);
}
}
```
阅读全文