json - groovy.json.JsonSlurper解析JSON

标签 json parsing groovy gradle

我正在尝试在gradle任务中解析JSON文件。

码:

def jsonFile = "../files/json/myJSON.json"
def list = new JsonSlurper().parseText(jsonFile)

JSON-文件
{
   "prepare": {
       "installed": [],
       "uninstalled": []
   },
   "config": {
       "files": []
   }
}

但是代码给了我以下异常:
Lexing failed on line: 1, column: 1, while reading '.', no possible valid JSON value or punctuation could be recognized.

而且我不明白为什么,我也在http://jsonlint.com/上验证了我的JSON文件,它说这是有效的JSON!

最佳答案

上面的代码试图将字符串../files/json/myJSON.json解析为JSON。而是使用:

def jsonFile = new File("../files/json/myJSON.json")
def map = new JsonSlurper().parse(jsonFile)

关于json - groovy.json.JsonSlurper解析JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24953522/

相关文章:

json - 在 Azure 数据工厂中使用嵌套 JSON 对象

javascript - 如何在 d3 图中使用 json 数组

java - 解析 Android Volley JSONArray 响应

java - 简单字符串拆分

grails - 在Grails cucumber 测试中使用I18N消息

json - Groovy:验证 JSON 字符串

c# - 覆盖 Json 反序列化带有前导零的数字作为十进制而不是八进制值

jquery - 解析多级JSON

java - 错误 : java. io.NotSerializedException : groovy. util.slurpersupport.Attributes

javascript - 如何用 Peg.js 打开文件?