Grails groovy:将字符串(即列表)转换为groovy列表

Grails groovy:将字符串(即列表)转换为groovy列表,grails,groovy,Grails,Groovy,这就是我正在做的。我想在版本列表上迭代。而且似乎很难找到解决办法 这是我打印版本列表时出现的错误: import groovy.json.JsonSlurper def ver = "['a', 'b', 'c']" def jsonSlurper = new JsonSlurper() def ver_list = jsonSlurper.parseText(ver) println ver_list 有效的json字符串必须是双引号 因此,在这行代码中进行更改,应该可以: Caught:

这就是我正在做的。我想在
版本列表
上迭代。而且似乎很难找到解决办法

这是我打印版本列表时出现的错误:

import groovy.json.JsonSlurper

def ver = "['a', 'b', 'c']"
def jsonSlurper = new JsonSlurper()
def ver_list = jsonSlurper.parseText(ver)
println ver_list

有效的json字符串必须是双引号

因此,在这行代码中进行更改,应该可以:

Caught: groovy.json.JsonException: Unable to determine the current character, it is not a string, number, array, or object

The current character read is ''' with an int value of 39
Unable to determine the current character, it is not a string, number, array, or object
line number 1
index number 1
['a', 'b', 'c']
.^
groovy.json.JsonException: Unable to determine the current character, it is not a string, number, array, or object

The current character read is ''' with an int value of 39
Unable to determine the current character, it is not a string, number, array, or object
line number 1
index number 1
['a', 'b', 'c']
但是,如果需要解析无效的json,可以尝试LAX解析器

然后甚至可以解析以下字符串

def ver = '["a", "b", "c"]'

我不确定是什么问题。字符串不是列表,它是列表的文本表示形式。将其解析为JSON后会出现什么问题?如果你把它打印出来,我看不到任何迭代或其他的尝试。啊,我写得不好。让我编辑这个问题。有效的json字符串应该是双引号
import groovy.json.JsonSlurper
import groovy.json.JsonParserType

def ver = "[a, 'b', 001]"
def jsonSlurper = new JsonSlurper().setType( JsonParserType.LAX )
def ver_list = jsonSlurper.parseText(ver)
println ver_list