[英]How to convert a structure of type "buffer" to a json array in NodeJs and Express
當我用 https npm 模塊調用我的 api 時,它返回這個結構:
{"type":"Buffer","data":[55,74,49,66,73,102,85,]}
我想要的是 JSON 文件。 我該如何轉換它?
如果你得到這個緩沖區通常意味着數據還沒有完成到達,所以我這樣解決了我的問題:
var data = "";
//Function to recieve the JSON even it's too long
res.on("data", function (chunk) {
data += chunk;
});
//As I stop reciving data I send back the response
res.on("end", function () {
data = JSON.parse(data);
resp.send({
message: "Ok",
status: 200,
data: data,
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.