【问题标题】:How to read the chunking stream using node.js如何使用 node.js 读取分块流
【发布时间】:2015-05-03 18:36:31
【问题描述】:

以下是搜索交易的braintree api。结果作为流接收。但无法以字符串或所需格式读取接收到的块。

var stream = gateway.transaction.search(function (search) {
  result = search.paymentMethodToken().is("h337xg");

});

completeData = ""
stream.on("data", function(chunk){
        // read the chunk
        completeData += chunk;
});
stream.on("end", function(){
    // print the output in console 
    console.log(completeData);
});

stream.resume();

可以在控制台中看到的输出如下: [对象对象][对象对象][对象对象][对象对象][对象对象][对象对象][对象对象]

【问题讨论】:

  • 你试过 console.log(JSON.stringify(chunk)) 吗?它可能是 JSON 而不是字符串

标签: node.js braintree chunking


【解决方案1】:

(我在布伦特里工作)

返回的数据是一个 JSON 对象。为了将所有响应连接在一起,您需要有这样的东西:

completeData += JSON.stringify(chunk);

如果您对此有任何其他问题,请随时通过 support@braintreepayments.com 向我们的支持团队发送电子邮件

【讨论】:

    猜你喜欢
    • 2023-03-20
    • 1970-01-01
    • 2022-01-15
    • 2016-06-05
    • 2013-06-10
    • 1970-01-01
    • 1970-01-01
    • 2016-10-16
    • 2019-05-23
    相关资源
    最近更新 更多