I am trying to parse the json of Riot's League of Legend, but I found out it's difficult for me since I am a beginner. Hope someone can help me out, many thanks. Here is a part of the json:
我正在试图解析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"
}
...
}
}
Should I declare a class for each champion(which means I have to declare over one hundred classes), or is there a simple way to get this done?
我应该为每个冠军宣布一个班级(这意味着我必须宣布超过一百个班级),还是有一个简单的方法来完成这个?
1 个解决方案
#1
2
You can make your model generic for this i would recommend to read about generic programming. Use this link as a reading material
你可以让你的模型通用,我建议读一下通用编程。使用此链接作为阅读材料
Use jsontopojo
a web tool. Just to go this site. Past your valid json and it will produces classes itself. http://www.jsonschema2pojo.org/
使用jsontopojo一个Web工具。只是去这个网站。过去你的有效json,它将自己产生类。 http://www.jsonschema2pojo.org/
Note: You gotta select JSON as source type in the web tool.
注意:您必须在Web工具中选择JSON作为源类型。
#1
2
You can make your model generic for this i would recommend to read about generic programming. Use this link as a reading material
你可以让你的模型通用,我建议读一下通用编程。使用此链接作为阅读材料
Use jsontopojo
a web tool. Just to go this site. Past your valid json and it will produces classes itself. http://www.jsonschema2pojo.org/
使用jsontopojo一个Web工具。只是去这个网站。过去你的有效json,它将自己产生类。 http://www.jsonschema2pojo.org/
Note: You gotta select JSON as source type in the web tool.
注意:您必须在Web工具中选择JSON作为源类型。