第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何從非列表格式的 JSON 對(duì)象在 GSON 中創(chuàng)建列表?

如何從非列表格式的 JSON 對(duì)象在 GSON 中創(chuàng)建列表?

有只小跳蛙 2021-07-16 17:08:36
我正在嘗試將 JSON 對(duì)象轉(zhuǎn)換為 POJO,理想情況下我會(huì)collection在我的cluster對(duì)象中有一個(gè)(的)對(duì)象列表。然而,JSON 模式不使用列表,它使用collection名稱(chēng)的映射,該映射未知且可能會(huì)更改。有沒(méi)有辦法使用 GSON 將其轉(zhuǎn)換為 POJO 列表?有問(wèn)題的 JSON:{  "responseHeader":{    "status":0,    "QTime":333},  "cluster":{    "collections":{      "collection1":{        "shards":{          "shard1":{            "range":"80000000-ffffffff",            "state":"active",            "replicas":{              "core_node1":{                "state":"active",                "core":"collection1",                "node_name":"127.0.1.1:8983_solr",                "base_url":"http://127.0.1.1:8983/solr",                "leader":"true"},              "core_node3":{                "state":"active",                "core":"collection1",                "node_name":"127.0.1.1:8900_solr",                "base_url":"http://127.0.1.1:8900/solr"}}},          "shard2":{            "range":"0-7fffffff",            "state":"active",            "replicas":{              "core_node2":{                "state":"active",                "core":"collection1",                "node_name":"127.0.1.1:7574_solr",                "base_url":"http://127.0.1.1:7574/solr",                "leader":"true"},              "core_node4":{                "state":"active",                "core":"collection1",                "node_name":"127.0.1.1:7500_solr",                "base_url":"http://127.0.1.1:7500/solr"}}}},        "maxShardsPerNode":"1",        "router":{"name":"compositeId"},        "replicationFactor":"1",        "znodeVersion": 11,        "autoCreated":"true",        "configName" : "my_config",        "aliases":["both_collections"]      }    },    "aliases":{ "both_collections":"collection1,collection2" },    "roles":{      "overseer":[        "127.0.1.1:8983_solr",        "127.0.1.1:7574_solr"]    },    "live_nodes":[      "127.0.1.1:7574_solr",      "127.0.1.1:7500_solr",      "127.0.1.1:8983_solr",      "127.0.1.1:8900_solr"]  }}
查看完整描述

2 回答

?
忽然笑

TA貢獻(xiàn)1806條經(jīng)驗(yàn) 獲得超5個(gè)贊

您可以使用 TypeAdapter 將您的對(duì)象轉(zhuǎn)換為對(duì)象列表,或者只是將所有對(duì)象cluster放入 aJsonArray然后將其解析為 a List<Collection>,如下所示:


JsonArray jsonArr = new JsonArray();


JsonObject fullObj = new GsonBuilder().create().fromJson(jsonStr, JsonObject.class);

fullObj.getAsJsonObject("cluster")

    .entrySet()

    .forEach(col -> jsonArr.add(col.getValue()));


List<Collection> collections = gson.fromJson(jsonArr.toString(), Collection.class);


查看完整回答
反對(duì) 回復(fù) 2021-07-29
  • 2 回答
  • 0 關(guān)注
  • 202 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)