如何使用groovy为数组赋值?

时间:2013-02-12 08:02:50

标签: groovy

响应:

[
    {"msisdn":"85237009372","name":"Vicky","carrier":"AIRTEL"},
    {"msisdn":"85237009373","name":"Vicky1","carrier":"AIRTEL"}
]

我想从响应中提取所有名称并将其分配给数组/列表?

代码:

import groovy.json.JsonSlurper

// Retrieve valid mptu Amounts from GET mptu-amounts response
context.responseContent = context.testCase.getTestStepByName("xxxx").getPropertyValue("r_responseContent")

try
{
  responseContentParsed = new JsonSlurper().parseText( context.responseContent )

  context.mptuValidAlias = responseContentParsed.name[0]
  log.info(context.mptuValidAlias)
}

它正在检索第一行,名称(即)vicky ..我想提取所有行的名称并将其分配给列表..如何做到这一点?

1 个答案:

答案 0 :(得分:1)

更改此行:

context.mptuValidAlias = responseContentParsed.name[0]

到此:

context.mptuValidAlias = responseContentParsed.name