9

我可以使用 Unirest 来获取我自己的类的对象,如下所示:

HttpResponse<Item> itemResponse = Unirest.get("http://localhost:8080/item").asObject(Item.class);

我还可以将 type 参数设置为List,这确实给了我一个哈希映射列表,但我想获得一个项目列表。这可能吗?

4

2 回答 2

26

不知道您是否还在等待答案,但您应该使用数组。像这样;

HttpResponse<Item[]> itemResponse = Unirest.get("http://localhost:8080/item").asObject(Item[].class);
于 2016-01-09T00:38:42.593 回答
3

除了@scuro 的答案,您还可以从这样的响应中获取对象列表:

List<Item> items = Unirest.get("http://localhost:8080/item")
              .asObject(new GenericType<List<Item>>(){})
              .getBody();

来自Unirest Docs。

于 2020-12-26T14:30:00.870 回答