Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
邮递员Jetpack解析json响应_Json_Api_Testing_Postman_Jetpack - Fatal编程技术网

邮递员Jetpack解析json响应

邮递员Jetpack解析json响应,json,api,testing,postman,jetpack,Json,Api,Testing,Postman,Jetpack,我在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(re

我在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解析并存储到变量中?

如何:

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

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