好的数据库网站,wordpress 粘贴,做网站的样版,免费成品网站模板下载目前前端获取除了太平洋#xff0c;没有其它的了。
//在JS中都是使用的UTF-8#xff0c;然而requst请求后显示GBK却是乱码#xff0c;对传入的GBK字符串#xff0c;要用数据流接收#xff0c;responseType: arraybuffer
tt.request({url: https://whoi…目前前端获取除了太平洋没有其它的了。
//在JS中都是使用的UTF-8然而requst请求后显示GBK却是乱码对传入的GBK字符串要用数据流接收responseType: arraybuffer
tt.request({url: https://whois.pconline.com.cn/ipJson.jsp?jsontrue,data: {},header: { content-type: application/json },method: POST,dataType: JSON,responseType: arraybuffer,success(res) {//获取用户的位置信息console.log(获取用户的地区信息);var x new Uint8Array(res.data);var str new TextDecoder(gbk).decode(x);console.log(JSON.parse(str).pro JSON.parse(str).city);},fail(res) {console.log(获取地区信息失败: JSON.stringify(res));}
});
当然出包后TextDecoder会找不到H5吗阉割版的web少啥东西也很正常。
下载两个三方库文件来源小程序实现GBK编码数据转为Unicode/UTF8 - 超软毛毛虫 - 博客园
引入用require不要用import不支持。 部分代码修改为
var x new Uint8Array(res.data);
var str new encoding.TextDecoder(gbk).decode(x);
console.log(JSON.parse(str).pro JSON.parse(str).city); 输出
{ip: xx.1.xx.xx, pro: 北京市, proCode: 1xxxxxx, city: 海淀区, cityCode: 1xxxxxxx, …}