我正在使用RestAssured,我正在得到这样的响应-
{
"Data": {
"Sub": {
"SubDetails": [
{
"OrgId": 5,
"SubId": 1,
"SubName": "Mathematics"
}
]
}
},
"RawData": {
"Url": "http://localhost:11111/cases/case-15",
"Type": "Rest",
"Request": {
"Details": {
"OrganizationId": 5,
"Student": {
"Age": 30,
"Religion": "Hindu",
"StudentId": 10
}
}
},
"Response": {
"SmartReturnObject": {
"Subject": [
{
"SubjectId": 1,
"SubjectName": "Mathematics"
}
],
"OrganizationId": 5
}
},
"IsApiError": false
},
"SessionId": "5q0",
"RequestUniqueId": "4543534",
"StatusCode": "4540000",
"StatusMessage": "Success",
"DataSource": "DD"
}
现在我需要分别提取Data对象和RawData对象,但是我失败了。我也尝试了JSONPath,但没有以JSON格式获取它。我尝试过
JsonPath body= response.jsonPath();
Object value=body.get("Data");
System.out.println("Value is-"+value);
并且像这样得到它-{Sub={SubDetails=[{OrgId=5, SubId=1, SubName=Mathematics}]}}
我希望响应为instanceof JSONObject或JSONArray类型。
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
尝试以下-
Gson gson = new Gson(); try { JSONObject obj = new JSONObject(gson.toJson(givenString)); }catch (Exception e){ System.out.println(e.toString()); }