json - 无法解析 AWS.EC2.describeInstances() 方法在 nodejs API 中返回的 JSON

标签 json node.js amazon-web-services amazon-ec2 ec2-api-tools

这是我的代码

var AWS = require('aws-sdk');
AWS.config.region = 'ap-southeast-1';

var uuid = require('node-uuid');
ec2 = new AWS.EC2({apiVersion: 'latest'});


AWS.config.update({accessKeyId: xxxxxxxx, secretAccessKey: yyyyyyyyyyy});
AWS.config.update({region: 'zzzzzzzzzzzzzz'});

var util = require('util');
var opsworks = new AWS.OpsWorks();
var cloudformation = new AWS.CloudFormation();
var cloudwatch = new AWS.CloudWatch();

function listInstances(callback){
new AWS.EC2().describeInstances(function(error, data) {
    if (error) {
        callback(error);
    } else {
        callback(util.inspect(data, {depth: null})); //this returns a full fledged JSON response on the console

}

});
}

//Test above methods
listInstances(callback);


function callback(data){
  console.log(data);
}

我尝试通过替换行来解析 JSON 响应

callback(util.inspect(data, {depth: null})); 

JSON.parse(data);

出现以下错误

{ [SyntaxError: Unexpected token o] statusCode: 200, retryable: false }
{ [200: null]
message: null,
code: 200,
time: Tue Jul 22 2014 22:59:42 GMT+0530 (India Standard Time),
statusCode: 200,
retryable: false }

我尝试使用 eval() 来解析它,但出现以下错误

[SyntaxError: Unexpected identifier]

我做错了什么吗,我应该使用任何其他逻辑来解析 JSON 响应吗?

请原谅我的无知,因为我是 node.js 和 AWS 的新手

最佳答案

似乎不需要解析数据,因为它已经解析过了。

看这个答案,是类似的问题。

I keep getting "Uncaught SyntaxError: Unexpected token o"

关于json - 无法解析 AWS.EC2.describeInstances() 方法在 nodejs API 中返回的 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24894059/

相关文章:

php - jQuery JSON - 为什么我收到以下错误?

Javascript JSON 不解析

javascript - Hapi.js 内容协商

node.js - 如何在不重启服务器的情况下将expressjs静态模板部署到AWS?

javascript - 如何遍历 JSON 对象定位特定属性并将其内容推送到数组?

json - Angular 2 应用程序部署到 Azure 时出现错误 404

node.js - Sharepoint请求摘要值跨域

javascript - 为什么 node.js 提示我的数组?

amazon-web-services - 是否可以将 AppSync API 端点限制为仅在网络中?

ruby-on-rails - CarrierWave 不适用于 Fog 和 S3 : ArgumentError. 。 ."is not a recognized storage provider"