groovy.json.JsonSlurper解析JSON [英] groovy.json.JsonSlurper parse JSON

查看:352
本文介绍了groovy.json.JsonSlurper解析JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



CODE:



<$ p

我试图在我的gradle任务中解析JSON文件。 $ p $ def jsonFile =../files/json/myJSON.json
def list = new JsonSlurper()。parseText(jsonFile)

JSON - FILE

  {
prepare:{
installed:[],
uninstalled:[]
},
config:{
files: []
}
}

但是代码给了我以下例外:

  Lexing在线失败:1,列:1,读取'。'时,没有可能的有效JSON值或标点符号认可。 

我不明白为什么,我还验证了我的JSON文件 http://jsonlint.com/ ,它表示它是一个有效的JSON!

../ files / json / myJSON.json 解析为JSON。取而代之的是使用:

$ p $ def jsonFile = new File(../ files / json / myJSON.json)
def map = new JsonSlurper()。parse(jsonFile)


I'm trying to parse a JSON-File in my gradle task.

CODE:

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

JSON - FILE

{
   "prepare": {
       "installed": [],
       "uninstalled": []
   },
   "config": {
       "files": []
   }
}

But the code gives me the following exception:

Lexing failed on line: 1, column: 1, while reading '.', no possible valid JSON value or punctuation could be recognized.

And I don't understand why, I also validated my JSON-File on http://jsonlint.com/ and it says that it is a valid JSON!

解决方案

Above code is trying to parse the string ../files/json/myJSON.json as JSON. Instead use:

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

这篇关于groovy.json.JsonSlurper解析JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆