gpt4 book ai didi

java - Json映射非标准接口(interface)

转载 作者:行者123 更新时间:2023-12-01 16:14:54 25 4
gpt4 key购买 nike

我得到了一个响应,它是对象的映射,但它们都有相同的键:

{
"hits": [
{
"recipe": {
"id" : "0",
"label" : "chicken noodles",
...
},
"another_field": "value"
},
{
"recipe": {
"id" : "1",
"label" : "fried chicken",
...
},
"another_field": "value"
},
{ "recipe": {...}, ... }
]
}

我的Pojo:

public class SearchRecipeResponse {

private List<RecipeResponse> hits;

public List<RecipeResponse> getHits() {
return hits;
}
}
public class RecipeResponse{
private String label;
...
getters, etc
}

结果以对象列表的形式出现,但所有对象均为空,因为 json 有效负载具有此键“recipe”。

最佳答案

您可以为配方创建 POJO 并将其用于映射。虽然不确定这就是您想要做的,但您需要扩展您的问题以增加清晰度。

关于java - Json映射非标准接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62427953/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com