在Groovy中将字符串转换为数组或列表

在Groovy中将字符串转换为数组或列表,groovy,soapui,ready-api,Groovy,Soapui,Ready Api,我正在使用Soap UI测试RESTFul Web服务。。 我已将[1,2,3,4,5….,10]作为PassedValue存储在属性中。。我必须将此值转换为数组或列表..,以便获取每个索引值 ExpectedValue = context.testCase.getPropertyValue("PassedValue") as String[] 这不管用。。如果我打印ExpectedValue[0],它会打印“[” 我想将ExpectedValue[0]提取为1,将第一个索引提取为2 试图转

我正在使用Soap UI测试RESTFul Web服务。。 我已将[1,2,3,4,5….,10]作为PassedValue存储在属性中。。我必须将此值转换为数组或列表..,以便获取每个索引值

ExpectedValue = context.testCase.getPropertyValue("PassedValue") as String[] 
这不管用。。如果我打印ExpectedValue[0],它会打印“[”

我想将ExpectedValue[0]提取为1,将第一个索引提取为2

试图转换为toList,但仍然没有成功


有人能帮我吗?

你可以使用Eval

比如,

def expectedValue = Eval.me(context.testCase.getPropertyValue("PassedValue"))

有关更多信息

您可以使用Eval

比如,

def expectedValue = Eval.me(context.testCase.getPropertyValue("PassedValue"))
更多信息

我喜欢@Gokhan的解决方案,但我把它作为替代方案

您可以使用
JsonSlurper
实现相同的功能:

import groovy.json.JsonSlurper;

def result = ​new JsonSlurper().parseText("[1,2,3]")

我喜欢@Gokhan的解决方案,但我把它作为替代方案

您可以使用
JsonSlurper
实现相同的功能:

import groovy.json.JsonSlurper;

def result = ​new JsonSlurper().parseText("[1,2,3]")