uni-app 后台返回数据在hbuilder中被更改了,问题很严重
uni-app 后台返回数据在hbuilder中被更改了,问题很严重
示例代码:
其中’console.log(res)’;就是打印的数据,数据和后台不一致
```javascript
return uni.request({
url: apiUrl,
method: method,
data: data||'',
dataType: 'json',
header: header,
}).then(res => {
console.log(res);
if (res[1].statusCode && res[1].statusCode == 200) {
return res[1].data
} else {
console.log('request fail:', JSON.stringify(res));
throw res[1]
}
})
操作步骤:
在微信开发者工具中打开这个链接http://h5.thomashe.cn/pages/pay?qrcode=byb881716390437634004719241,可以在控制台看到shopId字段,其实就是qrcode其中16390xxxx这一串
预期结果:
shopId应为16390437634004719
实际结果:
shopId变成了16390437634004720
bug描述:
H5应用通过uni.request调用后台接口,返回数据被修改了,详细看附件。 1图是后台打印的数据,2图是在浏览器控制台打印的数据,值被+1了,排查了很久没找到原因,觉得应该是个bug

| 产品分类 | PC开发环境操作系统 | PC开发环境操作系统版本号 | HBuilderX版本号 |
|---|---|---|---|
| HbuilderX | Windows | win10 | 3.2.16 |
更多关于uni-app 后台返回数据在hbuilder中被更改了,问题很严重的实战教程也可以访问 https://www.itying.com/category-93-b0.html
这个链接是在开发机环境,一般10点~晚上10点都能打开,打不开请留言
更多关于uni-app 后台返回数据在hbuilder中被更改了,问题很严重的实战教程也可以访问 https://www.itying.com/category-93-b0.html
jq ajax 请求呢?
没有用jq,那个兼容性不太好,后面这个H5可能会兼容到小程序端。这个情况出现过2次,很多是不理解
这是一个典型的 JavaScript 大整数精度丢失问题,不是 uni-app 或 HBuilderX 的 bug。
问题原因:
JavaScript 的 Number 类型使用 IEEE 754 双精度浮点数格式存储,能安全表示的最大整数是 2^53-1(即 9007199254740991)。你的 shopId 值 16390437634004719 已经超过了这个范围,导致精度丢失,显示为 16390437634004720。
解决方案:
- 后端处理:让后端将大整数以字符串形式返回,而不是数字类型。
- 前端处理:在 uni.request 中设置
dataType: 'json'时,JSON.parse 会自动将大数字转为 Number。可以尝试:- 使用
dataType: 'text'然后手动解析 JSON - 使用第三方库如
json-bigint处理大数字
- 使用
建议修改代码:
return uni.request({
url: apiUrl,
method: method,
data: data||'',
dataType: 'text', // 改为 text 类型
header: header,
}).then(res => {
const response = JSON.parse(res[1].data); // 手动解析
console.log(response);
if (res[1].statusCode && res[1].statusCode == 200) {
return response;
} else {
console.log('request fail:', JSON.stringify(res));
throw res[1]
}
})

