首页 > 后端开发 > php教程 > json_encode json_decode 整型溢出的问题

json_encode json_decode 整型溢出的问题

WBOY
发布: 2016-06-23 13:34:33
原创
1034 人浏览过

php版本5.2-5.3 不能升级到5.4的情况下 有下面一段代码

<?php$json='{"lastRev":20150517175733,"fileList":{"count":4,"folder":[{"id":915501363499340,"name":"demo","createDate":"2015-05-17 17:49:03","lastOpTime":"2015-05-17 17:49:03","rev":"20150517174903"}],"file":[{"id":913031363216803,"name":"yueyuhuashi..mp4","size":28444469,"md5":"179954914C459FE29885A077A1A62B5E","lastOpTime":"2015-05-17 10:45:31","createDate":"2015-05-17 10:45:31","mediaType":3,"rev":"20150517104531"},{"id":613031363569707,"name":"多元神话 - 火火中国风(广场舞版).mp3","size":15436145,"md5":"1700981A8F72B46F2ED50914D7F0F997","lastOpTime":"2015-05-17 10:42:44","createDate":"2015-05-17 10:42:44","mediaType":2,"rev":"20150517104244"},{"id":113991363195034,"name":"7.jpg","size":1851,"md5":"0A7211CE8E736AD4E2CE36E18CC08E65","lastOpTime":"2015-05-17 10:17:41","createDate":"2015-05-17 10:10:36","mediaType":1,"rev":"20150517101741"}]}}';$obj=json_decode($json,true);print_r($obj);exit;
登录后复制



输出的是:


Array(    [lastRev] => 20150517175733    [fileList] => Array        (            [count] => 4            [folder] => Array                (                    [0] => Array                        (                            [id] => 9.1550136349934E+14                            [name] => demo                            [createDate] => 2015-05-17 17:49:03                            [lastOpTime] => 2015-05-17 17:49:03                            [rev] => 20150517174903                        )                )            [file] => Array                (                    [0] => Array                        (                            [id] => 9.130313632168E+14                            [name] => yueyuhuashi..mp4                            [size] => 28444469                            [md5] => 179954914C459FE29885A077A1A62B5E                            [lastOpTime] => 2015-05-17 10:45:31                            [createDate] => 2015-05-17 10:45:31                            [mediaType] => 3                            [rev] => 20150517104531                        )                    [1] => Array                        (                            [id] => 6.1303136356971E+14                            [name] => 多元神话 - 火火中国风(广场舞版).mp3                            [size] => 15436145                            [md5] => 1700981A8F72B46F2ED50914D7F0F997                            [lastOpTime] => 2015-05-17 10:42:44                            [createDate] => 2015-05-17 10:42:44                            [mediaType] => 2                            [rev] => 20150517104244                        )                    [2] => Array                        (                            [id] => 1.1399136319503E+14                            [name] => 7.jpg                            [size] => 1851                            [md5] => 0A7211CE8E736AD4E2CE36E18CC08E65                            [lastOpTime] => 2015-05-17 10:17:41                            [createDate] => 2015-05-17 10:10:36                            [mediaType] => 1                            [rev] => 20150517101741                        )                )        ))
登录后复制



可以发现  [id] =>  已经溢出了  求解决办法


回复讨论(解决方案)

你不给长数字加上引号,哪能怪谁呢?

版主 那个json 是不可控的  人家API提供的就是这样的数据,,,,,

$json = preg_replace('/("id":)(\d{9,})/i', '${1}"${2}"', $json);   结贴搞定

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板