[英]How to get JSON object from array of JSON objects in postman?
Looked for while on other threads and questions didn't get how to get JSON object in array questions I have already looked at - How to get JSONobject from JSONArray in postman 在其他线程上寻找了一段时间,但问题没有得到我已经看过的数组问题中的如何获取JSON对象- 如何在邮递员中从JSONArray中获取JSONobject
How to get array from JSON Object? 如何从JSON对象获取数组?
what I have tried so far - 到目前为止我尝试过的-
var jsonData = JSON.parse(responseBody);
var jsonObject = jsonData.events[2];
console.log("jsonobject - " + jsonObject);
console output - 控制台输出-
jsonobject - [object Object]
json response looks like this - json响应看起来像这样-
[
{
"$ts": "2019-06-14T06:21:55.2221392Z",
"values": [
"43912",
"CountIn",
"neet.row.mac3.indexinput",
"mac3",
"mac3",
"mac3",
300,
11,
1,
"mac3",
"2019-06-14T06:21:55.2221392Z",
"2019-06-14T06:22:55.2221392Z",
"manager",
"lead",
"consultant",
"5ca1e66d7eb20a11f00e502c
]
},
{
"$ts": "2019-06-14T06:23:54.3263475Z",
"values": [
"44272",
"indexinput",
"neet.row.mac2.indexinput",
"mac2",
"mac2",
"mac2",
300,
11,
1,
"mac2",
"2019-06-14",
"2019-06-14",
"Head",
"Master",
"Student",
"5ca1e66d7eb20a11f00e502c"
]
},
{
"$ts": "2019-06-14T06:24:54.3753534Z",
"values": [
"44452",
"indexinput",
"neet.row.mac.indexinput",
"mac",
"mac",
"mac",
300,
11,
1,
"Neet",
"2019-06-14T06:24:54.3753534Z",
"something1",
"something2 of something1",
"something3 of something2 ",
"5ca1e66d7eb20a11f00e502c"
]
}
]
Looks like you are getting the object, but the console is printing it as [object Object]. 看起来您正在获取对象,但是控制台将其打印为[object Object]。 Try printing
jsonObject.$ts
or jsonObject.values[0]
to see if the object contains the data you are looking for. 尝试打印
jsonObject.$ts
或jsonObject.values[0]
以查看对象是否包含您要查找的数据。
This happened because jsonObject
is object of objects so when you say console.log(jsonObject) it will show you object values in postman's console. 发生这种情况是因为
jsonObject
是对象的对象,因此当您说console.log(jsonObject)时,它将在邮递员的控制台中向您显示对象值。 but postman console does not shows values of objects in console when it is appended to string message. 但是当邮递员控制台附加到字符串消息后,它不会在控制台中显示对象的值。 To see values inside object
stringify
it something like this - 要查看对象中的值将其
stringify
,如下所示:
console.log("jsonobject - " + JSON.stringify(jsonObject));
it will print values in console for your object 它将在控制台中为您的对象打印值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.