我试图用语表达以下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");
关于java - 解析JSON响应,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50583633/