java - 解析 JSON 响应
问题描述
我正在尝试使用下面的 json 响应并在 java中获取“ message
”和“ ”数据WORKORDERID
{
"operation": {
"result": {
"message": " successfully.",
"status": "Success"
},
"Details": {
"SUBJECT": "qqq",
"WORKORDERID": "800841"
}
}
}
下面是我的代码
JSONObject inputs = new JSONObject(jsonResponse);
JSONObject jsonobject = (JSONObject) inputs.get("operation");
String s = jsonobject.getString("message");
system.out.println("s");
解决方案
您的对象嵌套了 2 次,因此您应该这样做:
JSONObject inputs = new JSONObject(jsonResponse);
JSONObject operation= (JSONObject) inputs.get("operation");
JSONObject result= (JSONObject) operation.get("result");
JSONObject details= (JSONObject) operation.get("Details");
String message = result.getString("message");
String workerId = details.getString("WORKORDERID");
推荐阅读
- python - 有没有办法获取数据集列表以及 Big Query 中的表和视图?
- html - 在同一行中居中对齐三个或更多字体真棒图标
- unetstack - maxPropagationDelay 在 UnetStack 的链接代理中的作用
- winapi - WM_LBUTTONDOWN 在 DPI 150 的不同操作系统上接收不同的坐标
- image - Ubuntu 18.x + Apache 2 上的 http 图像似乎已损坏/不完整
- php - Laravel 6:如何在字段中使用客户验证消息
- reactjs - Android物理设备上的网络请求失败
- nginx - 从 NginX 中的代理传递语句中删除尾部斜杠
- node.js - 有没有办法从请求对象读取文件输入和文本输入,它作为多部分表单数据传递给 loopback2 POST API?
- ios - 无法将 Apple Watch 模拟器与 iPhone 模拟器同步以添加 SSL 证书