javascript - 如何从 NodeJS 中的 Json 对象列表中检索特定值
问题描述
我正在尝试下面的代码来检索executionArn但我收到了这个错误
Error [SyntaxError]: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>)
如何从每条记录中获取executionArn或stateMachineArn ?任何帮助将非常感激。
console.log(data) - 输出
{
executions: [
{
executionArn: 'arn:aws:states:us-east-2:12222:execution:test:dcb689bc',
stateMachineArn: 'arn:aws:states:us-east-2:12222:stateMachine:test-sm',
name: 'test-name',
status: 'SUCCEEDED',
startDate: 2021-06-17T13:43:39.817Z,
stopDate: 2021-06-17T13:43:53.667Z
},
{
executionArn: 'arn:aws:states:us-east-2:12222:execution:test:sd32dsdf',
stateMachineArn: 'arn:aws:states:us-east-2:12222:stateMachine:test-sm',
name: 'test-name1',
status: 'SUCCEEDED',
startDate: 2021-06-17T13:43:39.817Z,
stopDate: 2021-06-17T13:43:53.667Z
}
],
nextToken: 'aadfdfdf'
}
代码:
stepfunctions.listExecutions(params, function(err, data) {
if (err) console.log(err, err.stack);
else
console.log(data)
//console.log(data.executions[0].executionArn)
data = JSON.parse(data);
data.forEach(function(result) {
var arnValue = result.executions.executionArn;
console.log(arnValue);
});
});
解决方案
data 是一个对象,其中的执行是一个数组,所以试试这个
data.executions.foreach(function (execution) {
console.log('executionArn', execution.executionArn)
console.log('stateMachineArn', execution.stateMachineArn)
})
推荐阅读
- xamarin - Xmarin.forms iOS 检查捕获的照片是否包含人脸
- c# - 更新数据库 c# 控制台应用程序中的表行
- lex - /usr/bin/ld: 找不到 -ll collect2: 错误: ld 返回 1 退出状态
- asp.net-core - 请告诉我如何上传 Summernote 的文字图片
- javascript - 如何对使用赛普拉斯的 React 组件调用回调函数进行单元测试
- firebase - 在颤振飞镖应用程序中出现错误。未为“DocumentSnapshot”类型定义运算符“[]”。尝试定义运算符'[]'
- sql - 添加 ROW_NUMBER 到查询是否会自动排序?
- reactjs - 基于 onclick 按钮功能在循环中调用反应组件,该功能在单击按钮后将状态设置为 true
- javascript - 为什么即使主执行堆栈为空,事件队列中的函数也不会被调用?
- assembly - 输出浮点