这是我的代码
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
的新手答案 0 :(得分:0)