Grails:获取和解析JSON时出错

时间:2014-08-15 17:08:11

标签: json grails groovy

我有一个Grails服务,它向JIRA REST API发送请求并返回JSON - 当我尝试使用JsonSlurper来解析JSON时,我收到以下错误:

ERROR errors.GrailsExceptionResolver  - JsonException occurred when processing request: [GET] /osmDash/jira/storyComplete
Lexing failed on line: 1, column: 1, while reading 'j', no possible valid JSON value or punctuation could be recognized.

以下是控制器中的代码:

def jsonFile = jiraService.fetchJQL('issuetype=Story AND status in (Resolved,Closed,Done) AND resolved>=-30d') as JSON

def jiraSlurper = new JsonSlurper()

def jiraResult = jiraSlurper.parseText('jsonFile').total

当我在页面中呈现JSON时,这就是JSON的样子: {"total":1356,"issues":[],"startAt":0,"maxResults":0}

我看着groovy.json.JsonSlurper parse JSON,看起来很简陋,但我无法使用这种方法。我正在寻找将“总”值分配给变量。

这是返回JSON的服务:

def fetchJQL(String jql, Integer maxResults = 0, def fields = null) {
    jira.request(POST, JSON) { req ->
        uri.path = '/rest/api/2/search'
        headers.'Authorization' = authHash
        body = [jql: jql, maxResults: maxResults, fields: fields]

        response.success = { resp, json ->
            return json
        }

        response.failure = { resp ->
            println resp.statusLine.statusCode
            println resp.statusLine
        }
    }

0 个答案:

没有答案