我正在将Foo对象列表转换为JSON字符串.我需要将JSON字符串解析回Foos列表.但是在下面的示例中,解析为我提供了JSONObjects而不是Foos的列表.
例
List list = [new Foo("first"), new Foo("second")]
def jsonString = (list as JSON).toString()
List parsedList = JSON.parse(jsonString) as List
println parsedList[0].getClass() // org.codehaus.groovy.grails.web.json.JSONObject
Run Code Online (Sandbox Code Playgroud)
我怎样才能把它解析成Foos呢?提前致谢.
以下是我的 JSON 响应数据,我需要使用以下响应进行断言。我尝试了很多方法来编写 JSON 路径和期望值。总是断言失败。我想要的是请帮助写下以下数据的路径和期望值
{
"statusCode": 200,
"statusMessage": "Success",
"errorMessage": "",
"responseData": {
"id": 15,
"userName": "partner@tarento.com",
"firstName": "tarento",
"lastName": "test1",
"phoneNumber": "1234567812",
"email": "partner@tarento.com",
"password": "",
"city": "",
"agentList": [
{
"id": 37,
"userName": "Rahul.antonyRaj@tarento.com",
"firstName": "Sanjay",
"lastName": "rahul",
"phoneNumber": "7411269480",
"email": "Rahul.antonyRaj@tarento.com",
"password": "",
"active": true
},
{
"id": 68,
"userName": "jinesh.sumedhan@tareto.com",
"firstName": "jinesh",
"lastName": "sumedhan",
"phoneNumber": "9400993826",
"email": "jinesh.sumedhan@tareto.com",
"password": "",
"active": true
},
{
"id": 108,
"userName": "a.sanjayrahul@gmail.com",
"firstName": "Rahul",
"lastName": "Antony",
"phoneNumber": "9994590241",
"email": …Run Code Online (Sandbox Code Playgroud) 我的java.lang.String的形式
[[{"ABC":{"total":0,"failed":0,"skipped":0}}], [{"BCD": {"total":0,"failed":0,"skipped":0}}]]
Run Code Online (Sandbox Code Playgroud)
如何在Groovy中将其转换为json?