如何获取子节点 EntityPropertyValue
, ProductPropertyValueUId
, ProductPropertyValueDisplayName
在父节点下 ["Name": "PriorityUId"]
使用“放心”?
下面是代码片段
RequestSpecification request = RestAssured.given();
request.header("Content-Type", "application/json");
JSONObject requestParams = new JSONObject();
requestParams.put("data", "somedata");
request.body(requestParams.toJSONString());
Response response = request.post("url");
List<Map<String, String>> epv = response.jsonPath().getList("EntityPropertyValues");
for(int i=0;i<epv.size();i++)
{
if(epv.get(i).containsValue("PriorityUId"))
{
System.out.println(epv.get(i));
break;
}
}
我正在做一个sysout,我得到了下面整个数据块的响应。
{
"Name": "PriorityUId",
"Values": [
{
"EntityPropertyValue": "Critical",
"ProductPropertyValueUId": "00000019-0000-0000-0000-000000000033",
"ProductPropertyValueDisplayName": "Blocker"
},
{
"EntityPropertyValue": "Critical",
"ProductPropertyValueUId": "00000019-0000-0000-0000-000000000034",
"ProductPropertyValueDisplayName": "Critical"
},
{
"EntityPropertyValue": "High",
"ProductPropertyValueUId": "00000019-0000-0000-0000-000000000035",
"ProductPropertyValueDisplayName": "Major"
}
],
"DataTypeUId": "00100002-0007-0000-0000-000000000000",
"DisplayName": "Priority"
}
我怎样才能捕捉到我正在寻找的领域?
下面是整个json响应
{
"ProductInstance": "00000000-0000-0000-0000-000000000000",
"DataTypeUId": null,
"EntityPropertyValues": [
{
"Name": "ModifiedAtSourceByUser",
"Values": [],
"IsPropertyExists": true
},
{
"Name": "ModifiedAtSourceOn",
"Values": []
},
{
"Name": "PriorityUId",
"Values": [
{
"EntityPropertyValue": "Critical",
"ProductPropertyValueUId": "00000019-0000-0000-0000-000000000033",
"ProductPropertyValueDisplayName": "Blocker"
},
{
"EntityPropertyValue": "Critical",
"ProductPropertyValueUId": "00000019-0000-0000-0000-000000000034",
"ProductPropertyValueDisplayName": "Critical"
},
{
"EntityPropertyValue": "High",
"ProductPropertyValueUId": "00000019-0000-0000-0000-000000000035",
"ProductPropertyValueDisplayName": "Major"
}
],
"DataTypeUId": "00100002-0007-0000-0000-000000000000",
"DisplayName": "Priority"
}
]
}
1条答案
按热度按时间kpbwa7wx1#
获取响应主体的jsonpath视图
获取EntityPropertyValue的大小
循环遍历数组,直到找到所需的值,当前-
PriorityUId
如果匹配,则使用jsonpath获取值,