gpt4 book ai didi

java - 有没有更好的方法来实现 HashMap>>>?

转载 作者:行者123 更新时间:2023-12-01 07:52:04 26 4
gpt4 key购买 nike

我需要按以下格式创建 json 响应:

{"responseCode":"00",
"responseMessage":"Success",
"planList":[
{"category":"category1",
"details":...}
{"category":"category2",
"details":...}
{"category":"category3",
"details":...}
]}

我想出了HashMap<String, List<HashMap<String, List<Details>>>> ,但我觉得应该有更好的方法来做到这一点。请帮忙。

提前致谢。

最佳答案

我认为您需要创建具有所需字段的类。例如:

class MyResponse {
private String responseCode;
private String responseMessage;
private List<Category> categories;
}

class Category {
private String category;
private String details;
}

它将提高可读性。

关于java - 有没有更好的方法来实现 HashMap<String, List<HashMap<String, List<Details>>>>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35695531/

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