JSONException 错误 Grails
JSONException error Grails
Paring JSON 文件,使用 JsonSlurper
我的代码如下
String url = 'https://urlThatIWantToGoto'
String jsonFile = new JsonSlurper.parseText(new URL(url).text))
JSONArray jsonParse = new JSONArray(jsonFile)
每当我 运行 这段代码时,我都会收到如下错误打印
Caught: org.codehaus.groovy.grails.web.json.JSONException: Expected a ',' or '}' at character 982 of "MyJSONFile"
有趣的是,它适用于我的示例 JSON url 之一,而其他两个则失败。
(我已经检查并确认所有三个 url 都包含有效的 JSON 文件)
谁能告诉我我的代码有什么问题吗?
我成功了。这是代码:
def url = "https://gist.githubusercontent.com/lee910.../test2"
def jsonResponse = new JsonSlurper().parseText(new URL(url).text)
println "== ${jsonResponse.size()}: ${jsonResponse[0]}"
因此,请注意 jsonResponse
已经是一个数组,因此不需要 JSONArray。打印给出:
== 30: [course:[guid:2f093ff2-913b-4081-a800-238200f1c559], cr...
最后一件事。确保你的 slurper 属于 import groovy.json.JsonSlurper
以防万一。
Paring JSON 文件,使用 JsonSlurper
我的代码如下
String url = 'https://urlThatIWantToGoto'
String jsonFile = new JsonSlurper.parseText(new URL(url).text))
JSONArray jsonParse = new JSONArray(jsonFile)
每当我 运行 这段代码时,我都会收到如下错误打印
Caught: org.codehaus.groovy.grails.web.json.JSONException: Expected a ',' or '}' at character 982 of "MyJSONFile"
有趣的是,它适用于我的示例 JSON url 之一,而其他两个则失败。 (我已经检查并确认所有三个 url 都包含有效的 JSON 文件)
谁能告诉我我的代码有什么问题吗?
我成功了。这是代码:
def url = "https://gist.githubusercontent.com/lee910.../test2"
def jsonResponse = new JsonSlurper().parseText(new URL(url).text)
println "== ${jsonResponse.size()}: ${jsonResponse[0]}"
因此,请注意 jsonResponse
已经是一个数组,因此不需要 JSONArray。打印给出:
== 30: [course:[guid:2f093ff2-913b-4081-a800-238200f1c559], cr...
最后一件事。确保你的 slurper 属于 import groovy.json.JsonSlurper
以防万一。