json - 获取 JSON 数据数组中的最后一个字段
问题描述
我有下面的脚本,它根据我需要的路径拉回我需要的信息
let bodyData = pm.response.json()
let country = bodyData[2].Country
console.log(country)
pm.environment.set("country", country)
不必说 [2],无论作为邮递员请求的一部分,有多少对象被拉过,我都想撤回最后一个。
你能建议我怎么做吗?
解决方案
这应该对你有用,它使用的是应用程序内置的Lodash_.last
方法:
let country = _.last(bodyData).Country
推荐阅读
- regex - 使用 VBA RegEx 即时更改公式
- javascript - 你们在部署时会缩小 node.js 吗?
- c++ - 获取用 C/C++ 打印的最后一个字符串
- php - PHP - Predis 连接超时
- java - 在服务层使用 DTO 是一种好习惯吗?
- java - 为什么我的方法会覆盖数组中的位置
- flutter - 在 Flutter 中使用 FilePicker 设置最大文件大小
- amazon-web-services - AWS Hadoop MapReduce - 平均字数
- node.js - 如何成功地将我的节点应用推送到 Heroku?
- javascript - 如何处理 Node.JS 中的 UnhandledPromiseRejectionWarning