2015-01-15 136 views
0

我一直在为node.js使用新的平衡节点模块,它似乎是由Q承诺驱动的。我不应该做正确的事情,因为当我将平衡API文档的回复与我从此插件获得的回复进行比较时,它们完全不同。从平衡节点模块响应中检索链接和属性的问题

我试图通过运行创建客户:

balanced.marketplace.customers.create({ 
     name: "John Smith", 
     email: "[email protected]", 
     phone: "2222222222" 
    }) 
    .then(function(customer) { 
     // this prints out a big object which looks like the properties of the module, 
     // I expected this to print out the sample response as seen in the API docs. 
     console.log(customer); 

     // when i run this, it prints out the actual name that was added. 
     console.log(customer.name); 

     // but I can't seem to get the various source URLs that the sample response shows. 
    }); 

可能有人给我如何正确地做到这一点与平衡节点模块了坚实的例子吗?

回答

2

您在文档中看到的示例响应是来自cURL请求的JSON响应,可能不是您实际从客户端库中看到的响应。

也就是说,要获得一个很好的打印,你应该使用下面的方法,而不是执行console.log对象的格式化JSON表示:

function print(obj) { 
    console.log('string' === typeof obj ? obj : JSON.stringify(obj, null, 4)); 
} 
+1

,如果这是建立在库本身这将是真棒。 – mjallday 2015-01-15 18:02:23