首頁 > 後端開發 > php教程 > json_encode json_decode 整型溢出的问题

json_encode json_decode 整型溢出的问题

WBOY
發布: 2016-06-23 13:34:33
原創
1039 人瀏覽過

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
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板