【问题标题】:Postman Jetpack parse json responsePostman Jetpack 解析 json 响应
【发布时间】:2016-05-01 14:02:07
【问题描述】:

我在 Postman 中进行了一个测试,在那里我执行了一个 post 请求并需要解析 json 响应

响应如下所示:

{
"name": "John Doe",
"id": "123",
"children": [{
    "id": "A1",
    "name": "Jane Doe"
}, {
    "id": "A2",
    "name": "Jack Doe"
}]

}

我需要从响应中获取所有 3 个 id 并将它们存储到一个变量中。我试过这个:

var data = JSON.parse(responseBody);
postman.setGlobalVariable("nameId", data.id);

这样,id 123 被存储到 nameId 中。问题是如何解析 A1 和 A2 id 并将其存储到变量中?

【问题讨论】:

    标签: json api testing postman jetpack


    【解决方案1】:

    怎么样:

    var data = JSON.parse(responseBody);
    postman.setGlobalVariable("firstChildrenId", data.children[0].id);
    postman.setGlobalVariable("secondChildrenId", data.children[1].id);
    

    【讨论】:

      猜你喜欢
      • 2018-12-04
      • 2017-11-07
      • 2021-08-04
      • 2021-07-02
      • 1970-01-01
      • 2013-03-27
      • 1970-01-01
      相关资源
      最近更新 更多