简体   繁体   English

JavaScript:如何获取发布到我的代码中的 json.file?

[英]JavaScript: How can Get the json.file that it was post to my code?

Imagine if I want to wait to get JSON file If they post to me.想象一下,如果我想等待获取 JSON 文件,如果他们发布给我。 I can get it.我能得到它。 if it's not I waite for it.如果不是我等它。 I want to get it and store it and parse it to work on it.我想获取并存储它并解析它以进行处理。 (I need to receive the request )How I can have JSON file I can get it to take what I need then post my HTTP response to the agent that sends me file that file. (我需要接收请求)我如何拥有 JSON 文件,我可以让它获取我需要的内容,然后将我的 HTTP 响应发布到向我发送该文件的代理。

my JSON file name is : flow_demo_1我的 JSON 文件名是:flow_demo_1

 var device_array = { device_id : [["7547092d-e03e-5148-a54f-8276a85d7f70","cpp_node_192-168-56-1:6111"]] }; var from_file_array = [ { device_id_from_file: "7547092d-e03e-5148-a54f-8276a85d7f70" }, { device_id_from_file: "93e71ba7-fb56-5592-a5f6-d855203dd7ae" }, { device_id_from_file: "93e71ba7-fb56-5592-a5f6-d855203dd7ae" }, { device_id_from_file: "fe21abdf-706f-5c7b-adb8-2507e145e820" }, ]; var val = device_array['device_id'][0][0]; for (var i= 0; i < from_file_array.length; i++) { if(from_file_array[i].device_id_from_file === val){ console.log("device ids are matches"); }; };

try this,you just want the which file data is matched right?试试这个,你只想匹配哪个文件数据对吗?

from_file_array.filter(each=>each.device_id_from_file===device_array.device_id[0][0])

it will give the matched device_id_from_file;if not you will get empty array它将提供匹配的 device_id_from_file;如果不是,您将获得空数组

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM