node.js - 使用 Node.js 从 JSON 中搜索和获取价值
问题描述
我需要从下面的 json 中搜索“信息”并使用 node.js 获得如下响应。
请帮助解决这个问题。
JSON文件
{
"call": "Info",
"locator": "test.so",
"classname": "DeviceInfo",
"autostart": true,
"state": "activated",
"module": "Plugin",
}
回复
Info,test.so,DeviceInfo,true,activated,Plugin
我在下面尝试过并且只打印信息而不是所有数据。我需要使用信息搜索而不是调用
var fs = require("fs");
var content = fs.readFileSync("D:/Test1.json");
var objectValue = JSON.parse(content);
console.log(objectValue.call);
解决方案
您可以Object.values(...)
按照此处所述使用:https ://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Object/values
var fs = require("fs");
var content = fs.readFileSync("D:/Test1.json");
var objectValue = JSON.parse(content);
// output: [ 'Info', 'test.so', 'DeviceInfo', true, 'activated', 'Plugin' ]
推荐阅读
- java - 浏览器未针对第二个 TestNG 测试用例启动
- r - RStudio 中的 install_keras(),tensorflow 2.4.0 需要 gast==0.3.3,但是你有 gast 0.4.0,这是不兼容的
- git - 子树中的 Git 子模块?
- axapta - Microsoft D365 FnO - 将用户选项 > 工作流中的“在电子邮件中发送通知”复选框的默认值设置为 true
- jsf - 选择更改并单击离开后,rowsPerPageTemplate 下拉菜单消失
- python-3.x - 如何利用 pyspark 获取 impala db/tables 元数据?
- docker - docker-compose 给出错误:backend exited with code 2 backend | /bin/sh:语法错误:未终止的引号字符串
- excel - 如果我将光标放在特定单元格中,自动运行宏?
- javascript - 如何更改名称提示中的默认键盘语言?
- r - 减少程序计算时间的建议