介绍
本示例介绍使用第三方库的Axios获取GBK格式的网络数据时,通过util实现GBK转换UTF-8格式。该场景多用于需要转换编码格式的应用。
效果图预览
使用说明
直接进入页面就可获取GBK格式的用户名信息并进行解码操作。
实现思路
- 使用第三方库Axios获取网络数据,并将获取数据类型设置为ARRAY_BUFFER
- axios<string, AxiosResponse<string>, null>({
- method: "get",
- url: URL,
- responseType: 'ARRAY_BUFFER'
- })
- 使用util.TextDecoder方法进行解码操作。
- let textDecoder = util.TextDecoder.create('gbk', { ignoreBOM: true });
- let result = new Uint8Array(res.data);
- let resultString = textDecod
评论记录:
回复评论: