【发布时间】:2015-06-02 14:41:13
【问题描述】:
使用 JsonSlurper 解析 JSON 文件
我的代码如下所示
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 文件)
谁能告诉我我的代码有什么问题?
【问题讨论】:
-
你必须显示你收到的 json 字符串。添加`println JsonOutput.prettyPrint(jsonFile)`,让我们看看你有什么。该错误清楚地表明 json 字符串存在问题。
-
@mohsenmadi gist.githubusercontent.com/lee910705/116ddc48f9d1c08a81e4/raw/… gist.githubusercontent.com/lee910705/69f29ed04dc919eb1606/raw/… 这是两个引发此错误的 JSON 文件。不过,我在这两个文件中没有发现任何问题......
标签: json parsing grails jsonslurper