【发布时间】:2019-08-31 00:48:30
【问题描述】:
我需要打印来自不同 JSON 文件的信息(将在 args[0] 中指定)并打印它们。
所有可能的访问文件都显示为这样(这是 JSON 文件的缩短版本)
{
"DefinitionSource" : "",
"Heading" : "Valley Forge National Historical Park",
"RelatedTopics" : [
"FirstURL" : //url here
"Text" : "hello world"
},
{
"FirstURL" : //url here
"Text" : "hello world"
},
]
根据选择要访问的 JSON 文件,有许多不同的子类。对于指定的 JSON 文件,我需要访问标有“文本”的 JSON 文件中的所有字符串。这是我正在使用的代码:
JsonReader reader = Json.createReader(new StringReader(jsonString));
JsonObject mainObject = reader.readObject();
JSONObject RelatedTopic = json.getJSONObject("RelatedTopics");
String text = RelatedTopic.getString("Text");
System.out.println("Textual Description: " + text);
【问题讨论】:
-
不回答您的问题,只是为了让您知道,对变量的第一个字母使用大写字母不是好的做法...