【问题标题】:How to assign values to array using groovy?如何使用groovy为数组赋值?
【发布时间】:2013-02-12 08:02:50
【问题描述】:

回应:

[
    {"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。我想提取所有行的名称并将其分配给列表。如何做到这一点?

【问题讨论】:

    标签: groovy


    【解决方案1】:

    改变这一行:

    context.mptuValidAlias = responseContentParsed.name[0]
    

    到这里:

    context.mptuValidAlias = responseContentParsed.name
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-13
      • 1970-01-01
      • 1970-01-01
      • 2020-07-14
      • 2021-10-08
      • 1970-01-01
      相关资源
      最近更新 更多