代码之家  ›  专栏  ›  技术社区  ›  user8715994

使用Java重启库列出节点中的参数

  •  0
  • user8715994  · 技术社区  · 8 年前

    http://services.groupkt.com/country/search?text=lands 具有从GET请求返回的16条记录。在记录中,有一个名为“name”的参数。因此,有16个名称,每个名称都有一个唯一的值(国家)。我的意图是使用java和重新发布的库列出“name”参数的所有16个值。我试过这个:

    Response response = RestAssured.get("http://services.groupkt.com/country/search?text=lands").andReturn();
    String json = response.getBody().asString();
    JsonPath jp = new JsonPath(json);
    
    List<String> ls = from(response).getList("RestResponse.result.name");// The 'from' text displays an error
    

    1 回复  |  直到 8 年前
        1
  •  0
  •   HaC    8 年前

    尝试替换 from(response) from(jp)

    响应类(这是 get() 方法返回)还支持 jsonPath

    List names= get("http://services.groupkt.com/country/search?text=lands").jsonPath().getList("RestResponse.result.name");