TypeScript:将arraybuffer类型数据转换为json
通过axios发送http请求时,如果设置了
const httpArgs = {
method: 'GET',
url:/url/xxx,
params:{},
headers:{'Content-type':'application/octet-stream'},
responseType:'arraybuffer'
}
那么响应数据将被保存在arraybuffer类型的数组中,可以通过如下方式将其转为为json
const httpArgs = {
method: 'GET',
url:/url/xxx,
params:{},
headers:{'Content-type':'application/octet-stream'},
responseType:'arraybuffer'
};
axios.request(httpArgs).then(function (res) {
if(res.headers['content-type'].includes("application/json"))
{
const decoder = new TextDecoder('utf-8');
let retJson = JSON.parse(decoder.decode(res.data));
}
});
原文地址:https://blog.csdn.net/jiemashizhen/article/details/136025811
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!