Heim >Backend-Entwicklung >PHP-Tutorial >json_encode json_decode 整型溢出的问题

json_encode json_decode 整型溢出的问题

WBOY
WBOYOriginal
2016-06-23 13:34:331043Durchsuche

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);   结贴搞定

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:安装laravelNächster Artikel:php和html混编