【问题标题】:I'm trying to get a specific string of the json file我正在尝试获取 json 文件的特定字符串
【发布时间】:2021-10-01 18:42:51
【问题描述】:

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

我正在使用 Java 和 jsonpath 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 的值

编辑:我想知道作者,但我不工作。 Response String 和 JSON String 是对的 (https://www.reddit.com/r/gaming/new.json?sort=new)

【问题讨论】:

  • 您对此错误有何疑问?
  • 我用有用的信息更新了文本

标签: java json reddit


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-04
    • 1970-01-01
    • 2020-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-11
    相关资源
    最近更新 更多