javascript - 如何从jsondata中获取key的值

标签 javascript node.js json lambda amazon-sqs

{
"Records": [{
    "messageId": "20ea364e-3bc107b5c78c",
    "receiptHandle": "AQEB6DhNloFS4R66c=",
    "body": "1",
    "attributes": {
        "ApproximateReceiveCount": "1",
        "SentTimestamp": "15393506",
        "SenderId": "AROAJMTI6NE:errorLog",
        "ApproximateFirstReceiveTimestamp": "15393511"
    },
    "messageAttributes": {},
    "md5OfBody": "c4ca75849b",
    "eventSource": "aws:sqs",
    "eventSourceARN": "arn:aws:sqs:ap-suth-1:83362:escalateErrorStandardQueue",
    "awsRegion": "ap-south-1"
}]

}

我想获取键“body”的值,预期输出应该是:1

最佳答案

var data={
"Records": [{
    "messageId": "20ea364e-3bc107b5c78c",
    "receiptHandle": "AQEB6DhNloFS4R66c=",
    "body": "1",
    "attributes": {
        "ApproximateReceiveCount": "1",
        "SentTimestamp": "15393506",
        "SenderId": "AROAJMTI6NE:errorLog",
        "ApproximateFirstReceiveTimestamp": "15393511"
    },
    "messageAttributes": {},
    "md5OfBody": "c4ca75849b",
    "eventSource": "aws:sqs",
    "eventSourceARN": "arn:aws:sqs:ap-suth-1:83362:escalateErrorStandardQueue",
    "awsRegion": "ap-south-1"
}]
};
console.log(data.Records[0].body);

您只需通过data.Records[0].body即可访问数据。

关于javascript - 如何从jsondata中获取key的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52819332/

相关文章:

javascript - 具有两个一致单词的多行打字机效果

php - 在 js .html() 方法中包含 <?php 标签?

Javascript定位问题

javascript - 如何注销 ipcRenderer.on 事件监听器?

php - Jquery、ajax、json、mysql_query 不起作用

c# - 使用 Push-Sharp 库将 Json 发送到 APNS

javascript - 使用什么作为图像的悬停效果?

mysql - node-mysql2 和准备好的语句

java - DNODE 作为一种让 Java 调用 NodeJS 函数的方法?

json - REST:如何以 "shallow"的方式将 java 对象序列化为 JSON?