Home  >  Article  >  Backend Development  >  json_decode 长整数,丢失精度,为何 window xp,该怎么处理

json_decode 长整数,丢失精度,为何 window xp,该怎么处理

WBOY
WBOYOriginal
2016-06-13 09:59:531127browse

json_decode 长整数,丢失精度,为何 window xp
在下面的php转换中:tid的精度会丢失,后面4位,6788,变成了7000 ,为何呢?

str='{"receiver_address":"四川遂宁市","receiver_city":"遂宁市","receiver_district":"射洪县","receiver_mobile":"15228662928","receiver_name":"蔡","receiver_state":"四川省","receiver_zip":"100218","sid":"114757372016788","tid":114757372016788}';

print_r(json_decode($str));exit;

测试环境:
A:centOS5+php5* 可以正确转换,
B: window xp +php526+Apache2.2 ,出错,丢失精度。

谢谢关注的亲们。

------解决方案--------------------
114757372016788 如果是数值的话,已超出 32 位机器的长整形所能表示的范围

你应该将其当做字符串处理,跟 sid 一样


------解决方案--------------------
编码问题吧
------解决方案--------------------
给数字两边加引号成字符串试一试
------解决方案--------------------
linux上安装的php模块和window上安装的不同, 或者php的配置不同, 所以json_decode的计算方法不一样。

如果你不懂怎么弄, 最简单的方法是当字符串处理, 在js脚本里转回整型数字。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn