[英]How can i select a specific part of json data with nodejs?
i have a nodeJS script that listens to for a webhook and then adds the data to firebase, the following works well:我有一个 nodeJS 脚本,它监听 webhook,然后将数据添加到 firebase,以下效果很好:
let data = {
addresses: event.data["addresses"],
code: event.data["code"],
created_at: event.data["created_at"],
exchange_rates: event.data["exchange_rates"],
expires_at: event.data["expires_at"],
pricing: event.data["pricing"]
};
However, the pricing json contains a lot of junk and i would only like to add a specific part of the pricing json, below is an example of the json:但是,定价 json 包含很多垃圾,我只想添加定价 json 的特定部分,下面是 json 的示例:
"pricing": {
"theprice": "0000",
"junk": "111",
"junk1": 222,
"junk2": 333
},
I would only like to select 'theprice' from the json.我只想从 json 到 select 'theprice'。 I have tried the following:我尝试了以下方法:
pricing: event.data["pricing"],["theprice"]
However this does not work, what is the correct syntax?但是这不起作用,正确的语法是什么?
Since your pricing
is another object/map, you can get it with:由于您的pricing
是另一个对象/地图,您可以通过以下方式获得它:
event.data["pricing"]["theprice"]
(so without the comma) (所以没有逗号)
Alternatively, this also works:或者,这也有效:
event.data.pricing.theprice
i don't know if this is a relatable solution but try parsing the data to json then try pricing: event.data.pricing.theprice.我不知道这是否是一个相关的解决方案,但尝试将数据解析为 json 然后尝试定价:event.data.pricing.theprice。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.