Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.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/4/json/15.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/1/angularjs/22.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
Node.js 节点js从键获取值_Node.js_Json_Discord.js_Key - Fatal编程技术网

Node.js 节点js从键获取值

Node.js 节点js从键获取值,node.js,json,discord.js,key,Node.js,Json,Discord.js,Key,我需要帮助我正在尝试从json文件中检索值“802125586923257886”,我能做什么 { "801502579829112852": { "channel": "802125586923257886" }, "802163006698946570": { "channel": "802163007173951521" } } 我试过了

我需要帮助我正在尝试从json文件中检索值“802125586923257886”,我能做什么

{
  "801502579829112852": {
    "channel": "802125586923257886"
  },
  "802163006698946570": {
    "channel": "802163007173951521"
  }
}
我试过了,但没有结束

function jsonParser(stringValue) {
  var string = JSON.stringify(stringValue);
  var objectValue = JSON.parse(string);
}

console.log(jsonParser('801502579829112852'))

提前感谢您

您试图做的是从一个键中查找一个值,该值反过来又是使用Javascript在JSON字典中查找另一个键的值

您需要将JSON字符串保存到变量中,并将其解析到Javascript字典中:

json_dict = `{
  "801502579829112852": {
    "channel": "802125586923257886"
  },
  "802163006698946570": {
    "channel": "802163007173951521"
  }
}`

js_dict = JSON.parse(json_dict)
js_dict["801502579829112852"]["channel"]
然后,您可以访问Javascript字典的字段:

json_dict = `{
  "801502579829112852": {
    "channel": "802125586923257886"
  },
  "802163006698946570": {
    "channel": "802163007173951521"
  }
}`

js_dict = JSON.parse(json_dict)
js_dict["801502579829112852"]["channel"]
返回:

802125586923257886
//您的值已经是JSON格式。无需再次解析
var json_dict={
"801502579829112852": {
“频道”:“802125586923257886”
},
"802163006698946570": {
“频道”:“802163007173951521”
}
}
jsonParser(json_dict)
函数jsonParser(pvalue){
var chanldataobj=pvalue['801502579829112852']
console.log(chanldataobj['channel'])

}
您在哪里读取文件?