线程中的例外“主” java.lang.classcastException:java.util.linkedhashmap class de Class java.util.list。
使用REST保证Java框架时,我会收到以下错误。
Exception in thread "main" java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class java.util.List (java.util.LinkedHashMap and java.util.List are in module java.base of loader 'bootstrap')
at io.restassured.path.json.JsonPath.getList(JsonPath.java:375)
at qaflightsuppliers.QaFlightDXBLONResponseDebugValidation.main(QaFlightDXBLONResponseDebugValidation.java:94)
以下是我的代码。请更正我的代码。
List<String> jsonMapStringObjectResponse = response.jsonPath().get("recommendation");
for (int i = 0; i <= jsonMapStringObjectResponse.size(); i++)
{
List<String> jsonMapObjectResponse = response.jsonPath().getList("recommendation[" + i + "]");
System.out.print("ValidatingAirlineName="+jsonMapObjectResponse.add("validatingAirlineName"));
}
When working with REST Assured Java framework, I get the following error.
Exception in thread "main" java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class java.util.List (java.util.LinkedHashMap and java.util.List are in module java.base of loader 'bootstrap')
at io.restassured.path.json.JsonPath.getList(JsonPath.java:375)
at qaflightsuppliers.QaFlightDXBLONResponseDebugValidation.main(QaFlightDXBLONResponseDebugValidation.java:94)
Below is my code. Please correct my code.
List<String> jsonMapStringObjectResponse = response.jsonPath().get("recommendation");
for (int i = 0; i <= jsonMapStringObjectResponse.size(); i++)
{
List<String> jsonMapObjectResponse = response.jsonPath().getList("recommendation[" + i + "]");
System.out.print("ValidatingAirlineName="+jsonMapObjectResponse.add("validatingAirlineName"));
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在尝试将属性
推荐
作为list
,但实际上在JSON响应中,它是MAP
。因此,您必须更改:
要从
这个问题您的JSON可能看起来像这样:
通过此演示进行了测试和验证,这可能也是一个很好的阅读资源:
You are trying to read the attribute
recommendation
as aList
, but in reality in the JSON response it's aMap
.So you have to change:
to
Reverse engineered from this question your JSON probably looks something like this:
Tested and verified with this demo, which might be a good reading resource as well: