我正在尝试获取 json 文件的特定字符串

I'm trying to get a specific string of the json file

我正在尝试通过 reddit 的 json 文件获取作者或缩略图 url 等其他信息。但是如果我 运行 它,它只会响应错误:com.jayway.jsonpath.PathNotFoundException

我正在使用 Java 和 json 路径 api 来获取路径。

代码:

String url = "https://www.reddit.com/r/gaming/new.json?sort=new";

...

System.out.println("result after Reading JSON Response");
String json = response.toString();
Object document = Configuration.defaultConfiguration().jsonProvider().parse(json);

String author0 = JsonPath.read(document, "$.data[0].children[0].data.author");

System.out.println(author0);

一切正常,除了我无法获得 author0 的值

编辑: 我想知道作者,但我没有工作。响应字符串和 JSON 字符串是正确的 (https://www.reddit.com/r/gaming/new.json?sort=new)

您可以使用以下方法获取作者姓名;

String author0 = JsonPath.read(document, "$.data.children[0].data.author_fullname");