gpt4 book ai didi

java - Linkedhashmap里面的ArrayList of Objects,获取数据

转载 作者:行者123 更新时间:2023-12-01 09:24:18 25 4
gpt4 key购买 nike

编辑:我正在解析 JSON。 JSON 具有这种形式

  {
"responseObject": {
"slots_0": [
{ //SlotItem (date, string, int, boolean },
{ //SlotItem }
],
"slots_1": [
{ //SlotItem (date, string, int, boolean },
{ //SlotItem }
{ //SlotItem }
]
},
"messages" : "Hi Stackoverflow"
}

我无法用 slot_0、slot_1 解析我的响应,因为我可以有更多的响应,实际上我可以有 slot_n、responseObject 将是 SlotItems 数组的数组,如果我没有错的话。

我首先进行解析(因为我只需要responseObject)

Hashmap <String, String> response = (Hashmap<String, String>) response.get("responseObject")

之后我尝试制作一个 ArrayList<SlotItem []>

在编辑之前,我尝试过这种方式:

我想要一个对象数组的 ArrayList

ArrayList <SlotItem []> slotsinfo

在 ArrayList 内部我有这样的结构:
enter image description here

我想要一个简单的ArrayList,而不是LinkedHashMap。
因为我想通过这种方式检索信息

String storeId = slotsinfo.get(index).getStoreId();

在 SlotItem 内部,我有 getter 和 setter。

我尝试使用 get(index) 检索列表中的数据,但它不起作用。

最佳答案

看起来您有 ArrayList<LinkedHashMap<String, String>> ,不是ArrayList<SlotItem[]>

I want to get a simple ArrayList, not a LinkedHashMap. Because i want to retriever the information in this way

String storeId = slotsinfo.get(index).getStoreId();

好吧,那么您需要修复如何获取该数据以具有 ArrayList<SlotItem>

就目前情况而言,您应该能够做到

result.get(index).get("storeId");

编辑

尝试像这样获取 JSON,使得 responseObject数组的数组

{
"responseObject": [
[
{ //SlotItem (date, string, int, boolean },
{ //SlotItem }
],
[
{ //SlotItem (date, string, int, boolean },
{ //SlotItem }
{ //SlotItem }
]
],
"messages" : "Hi Stackoverflow"
}

关于java - Linkedhashmap里面的ArrayList of Objects,获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39962565/

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