node.js - 获取 json 数据时使用外部字符串时遇到问题
问题描述
我目前正在尝试使用字符串“region”在我的 JSON 文件中查找 JSON 的特定部分。
前任。配置区域。${region}
等于 config.regions.northeast(假设 hooks[i].regions[c] == 东北)
for (var c = 0; c < hooks[i].regions.length; c++) {
let region = JSON.stringify(hooks[i].regions[c]);
if (config.regions.`${region}`.includes(city)) {
webhook = config.hooks[i].webhook;
post(webhook, title, price, link, img, city, keyword);
}
}
解决方案
如果我理解你的问题。我相信您应该使用数组语法来访问您的对象:
for (var c = 0; c < hooks[i].regions.length; c++) {
let region = JSON.stringify(hooks[i].regions[c]);
if (config.regions[region].includes(city)) {
webhook = config.hooks[i].webhook;
post(webhook, title, price, link, img, city, keyword);
}
}
推荐阅读
- java - 在文本中搜索 REGEX 值
- c++ - CUDA:让内核将函数指针作为参数
- bezier - Inkscape 自动平滑节点背后的算法
- javascript - 数据方法中的数组在一种方法中得到更新,但在另一种方法中仍然为空
- javascript - 如何在 textarea ReactJS + Bootstrap 中创建制表符间距?
- c++ - 访问不正确的问题(代码如下)
- html - 如何将元素定位在滚动容器内的相对固定位置?
- reactjs - 更改 React Native NativeModules.UIManager.showPopupMenu 的背景颜色
- docker - 如何减少 docker 存储使用量
- license4j - 如何停用许可证