如何从 Atlassian 网站解析 jira 版本

How to parse of jira-versions from Atlassian website

我遇到了问题。 我必须从 Atlassian 网站解析 JSON 包含 list 的 jira-core 版本。

尝试使用 JsonSlurper 从网站解析 JSON 时,我收到一条错误消息:

"The current character read is 'd' with an int value of 100 Unable to determine the current character, it is not a string, number, array, or object line number 1 index number 0"

代码:

def http = new HTTPBuilder('https://my.atlassian.com/download/feeds/')
def html = http.get( path : 'current/jira-core.json')
def slurper = new groovy.json.JsonSlurper(type: JsonParserType.LAX).parse(html)
print slurper

我如何获得正确的 JSON 区块?

问题是,那不是 json...这是一个 jsonp 回调,所以有效的 json 包含在 downloads( ... ) javascript 通话

您可以使用正则表达式解开 URL 中的文本:

import groovy.json.*

def jsonp = new URL('https://my.atlassian.com/download/feeds/current/jira-core.json').text
def extract = jsonp =~ /^downloads\((.+)\)$/
if (!extract.matches()) {
    throw new RuntimeException("Bad jsonp!")
}
def parsed = new JsonSlurper().parseText(extract.group(1))

parsed.each { println it.description }

虽然这不能直接解决 JSON 与 JSONP 的问题,但如果您只是想使用 Jira 版本数据,还有一个名为 iapetus.fyi that provides Atlassian product version information, including the possibility of providing Firebase notifications 到您的应用程序以获取版本更改事件。