我可以使用 Unirest 来获取我自己的类的对象,如下所示:
HttpResponse<Item> itemResponse = Unirest.get("http://localhost:8080/item").asObject(Item.class);
我还可以将 type 参数设置为List
,这确实给了我一个哈希映射列表,但我想获得一个项目列表。这可能吗?
不知道您是否还在等待答案,但您应该使用数组。像这样;
HttpResponse<Item[]> itemResponse = Unirest.get("http://localhost:8080/item").asObject(Item[].class);
除了@scuro 的答案,您还可以从这样的响应中获取对象列表:
List<Item> items = Unirest.get("http://localhost:8080/item")
.asObject(new GenericType<List<Item>>(){})
.getBody();