[英]What is the correct way to store all the dynamic Json response strings to a list in restassured java?
public void getresponseString() {
for (int i = 0; i < getInfoResp.jsonPath().getInt("Map.List.size()"); i++) {
ArrayList<String> country = getInfoResp.jsonPath().get("Map.List[" + i + "]" + ".country");
}
}
JsonResponse:响应:
{
"plan": {
"program": "gtr",
"syter": "yes"
},
"Map": {
"List": [
{
"id": "tyt6577",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "us",
"triag": null
},
{
"id": "yyaqtf6327",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "aus",
"triag": null
},
{
"id": "676hwjsgvhgv",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "rus",
"triag": null
},
{
"id": "676hsdhgv",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "spa",
"triag": null
},
{
"id": "623ujhhgv",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "cha",
"triag": null
}
]
}
} }
In the above method, I try to store all the strings of Jsonresponse in List but I got this error finally " java.lang.String cannot be cast to java.util.ArrayList "在上述方法中,我尝试将 Jsonresponse 的所有字符串存储在 List 中,但最终出现此错误“ java.lang.String cannot be cast to java.util.ArrayList ”
What is the correct way to store all the dynamic strings to list?将所有动态字符串存储到列表的正确方法是什么?
Why don't you split the json
and store the response in the ArrayList<String>
为什么不拆分
json
并将响应存储在ArrayList<String>
ArrayList<String> list = new ArrayList<>(Arrays.stream(response.split(",")).collect(Collectors.toList()));
You can split it either by comma or any other String/Char您可以用逗号或任何其他字符串/字符拆分它
The easiest way to extract country
here is:在这里提取
country
的最简单方法是:
ArrayList<String> country = getInfoResp.jsonPath().get("Map.List.country");
//[us, aus, rus, spa, cha]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.