gpt4 book ai didi

java - 使用 Gson 解析复杂的 json 时遇到问题

转载 作者:行者123 更新时间:2023-12-02 03:37:04 25 4
gpt4 key购买 nike

我正在尝试解析 Riot 英雄联盟的 json,但我发现这对我来说很困难,因为我是初学者。希望有人能帮助我,非常感谢。这是 json 的一部分:

{
"type": "champion",
"version": "6.9.1",
"data": {
"Thresh": {
"id": 412,
"key": "Thresh",
"name": "Thresh",
"title": "the Chain Warden"
},
"Aatrox": {
"id": 266,
"key": "Aatrox",
"name": "Aatrox",
"title": "the Darkin Blade"
},
"Tryndamere": {
"id": 23,
"key": "Tryndamere",
"name": "Tryndamere",
"title": "the Barbarian King"
},
"Gragas": {
"id": 79,
"key": "Gragas",
"name": "Gragas",
"title": "the Rabble Rouser"
},
"Cassiopeia": {
"id": 69,
"key": "Cassiopeia",
"name": "Cassiopeia",
"title": "the Serpent's Embrace"
},
"AurelionSol": {
"id": 136,
"key": "AurelionSol",
"name": "Aurelion Sol",
"title": "The Star Forger"
},
"Ryze": {
"id": 13,
"key": "Ryze",
"name": "Ryze",
"title": "the Rogue Mage"
},
"Poppy": {
"id": 78,
"key": "Poppy",
"name": "Poppy",
"title": "Keeper of the Hammer"
},
"Sion": {
"id": 14,
"key": "Sion",
"name": "Sion",
"title": "The Undead Juggernaut"
}
...
}
}

我应该为每个冠军声明一个类别(这意味着我必须声明超过一百个类别),还是有一个简单的方法来完成此任务?

最佳答案

您可以使您的模型通用,我建议您阅读有关通用编程的内容。使用这个link作为阅读 Material

使用 jsontopojo 网络工具。只是为了去这个网站。通过你的有效 json,它会自己生成类。 http://www.jsonschema2pojo.org/

注意:您必须在网络工具中选择 JSON 作为源类型。

关于java - 使用 Gson 解析复杂的 json 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37324863/

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