简体   繁体   English

java json github-api git github pull-request循环获取jsonpath解析resttemplate spring spring-boot

[英]java json github-api git github pull-request loops get jsonpath parsing resttemplate spring spring-boot

I got a json String from request of github api (/repos/:owner/:repo/pulls). 我从github api (/repos/:owner/:repo/pulls).请求中得到了一个json字符串github api (/repos/:owner/:repo/pulls). Then I parsed it into a DocumentContext using JsonPath.parse(json). 然后,我使用JsonPath.parse(json).parsedDocumentContext JsonPath.parse(json).

Now I want to iterate over my DocumentContext using the read(path) function, but the github api does not have a size/length or amount of pull-requests. 现在,我想使用read(path)函数遍历我的DocumentContext ,但是github api没有大小/长度或数量的拉取请求。

String json = https://api.github.com/repos/:owner/:repo/pulls
DocumentContext dc = JsonPath.parse(json)

for (int i = 0; i < dc.read($.somethingLikeSize); i++){
  //get the objects
  private int id = dc.read($.[i]...);
  //...
}

As I guess, the open_issues_count or open_issues can be pull-requests, but they don't have to. 我猜想,open_issues_count或open_issues可以是请求请求,但它们不是必须的。

How can I iterate over my documentContext.read($.[i]...) without getting a PathNotFoundException ? 我如何在documentContext.read($.[i]...) without getting a PathNotFoundException遍历documentContext.read($.[i]...) without getting a PathNotFoundException

(PS: Please be gentle, I'm a newbie.) (PS:请保持温柔,我是新手。)

String json = "...";
DocumentContext dc = JsonPath.parse(json);
List<String> listOfValues = dc.read("$.[?].key");

then you can iterate over listOfValues 那么你可以遍历listOfValues

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM