[英]How can i search for an specified result[key + value] in a json with javascript?
I am developing a discord bot, which works with the shoppy api, right now.我正在开发一个不和谐的机器人,它现在可以与 shoppy api 一起使用。 My target is to filter the respone of the shoppy api and get a value and key.
我的目标是过滤shoppy api的响应并获得一个值和键。 All i have done is parsing the request result into an json object.
我所做的就是将请求结果解析为一个 json 对象。 This is my code - i replaces sensitive data
这是我的代码 - 我替换敏感数据
request("https://shoppy.gg/api/v1/orders/"+args[0], options ,function(error, response, body) {
if (*1) {
console.log("Result: " + body);
var info = JSON.parse(body);
const embed = new RichEmbed()
.setColor("#756cff")
.setDescription("Valid order ID. You have been given customer role!")
.setImage(client.user.displayAvatarURL);
message.channel.send(embed);
}else{
const embed = new RichEmbed()
.setColor("#756cff")
.setDescription("Please enter a valid ID!")
.setImage(client.user.displayAvatarURL);
message.channel.send(embed);;
}
});
So i want that *1 checks if the result is {"status":false,"message":"Requested resource not found"}.所以我希望 *1 检查结果是否为 {"status":false,"message":"Requested resource not found"}。 How can i do this?
我怎样才能做到这一点?
我不明白你的问题,但如果你需要对象的“键”和“值”,你可以使用 Object.entries(objectName) 如果你需要找到对象的“值”并且你知道对象的名称,你可以使用: objectName.key 或 objectName[“key”]
Just use a simple if statement to check if the property and value are in the object or not只需使用一个简单的 if 语句来检查属性和值是否在对象中
var obj={as:534,dsad:54,htyhty:65,delivered:1} obj.delivered==1?console.log(true):console.log(false)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.