2015-01-15 137 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