【发布时间】:2019-10-29 07:09:00
【问题描述】:
我正在尝试读取从 Opentdb 获取的文件并仅从特定键访问数据。
我已经尝试了所有给定的方法,包括 GSON 和 Json Simple,但最终出现了错误。
这是我的 JSON:
{
"response_code": 0,
"results": [
{
"category": "Sports",
"type": "multiple",
"difficulty": "easy",
"question": "Which of the following sports is not part of the triathlon?",
"correct_answer": "Horse-Riding",
"incorrect_answers": [
"Cycling",
"Swimming",
"Running"
]
},
{
"category": "Sports",
"type": "multiple",
"difficulty": "easy",
"question": "Which English football club has the nickname \u0026#039;The Foxes\u0026#039;?",
"correct_answer": "Leicester City",
"incorrect_answers": [
"Northampton Town",
"Bradford City",
"West Bromwich Albion"
]
},
我只想访问 类别、难度、问题、正确答案和错误答案。
【问题讨论】:
-
如果你不介意使用第三方库,我建议使用 Jackson,你可以在这里找到教程baeldung.com/java-json
-
谢谢,但我发现的最佳解决方案是将 Pojos 与 gson 一起使用。它就像一个魅力。
标签: java json jsonreader