note 72067 added to function.json-decode
| From: | pmeserve at hostmysite dot com | Date: | Sun, 31 Dec 2006 20:35:30 +0000 |
| Subject: | note 72067 added to function.json-decode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-121151@lists.php.net to get a copy of this message | ||
If you have any large incoming integers, json_decode will truncate them to a 32-bit int. The only
solution I've found is to force-convert them to a string before decoding. e.g. part of my
incoming json string contains this:
"id":4081382083758,
So to fix this ID getting truncated, I did:
<?php
$text = preg_replace('/"id":(\d+),/i',
'"id":"$1",', $text);
?>
The relevant part is wrapping the numeral in quotes, which forces json_decode to see it as a string
and not truncate it
----
Server IP: 216.194.113.175
Probable Submitter: 209.41.163.23
----
Manual Page -- http://www.php.net/manual/en/function.json-decode.php
Edit -- https://master.php.net/note/edit/72067
Del: integrated -- https://master.php.net/note/delete/72067/integrated
Del: useless -- https://master.php.net/note/delete/72067/useless
Del: bad code -- https://master.php.net/note/delete/72067/bad+code
Del: spam -- https://master.php.net/note/delete/72067/spam
Del: non-english -- https://master.php.net/note/delete/72067/non-english
Del: in docs -- https://master.php.net/note/delete/72067/in+docs
Del: other reasons-- https://master.php.net/note/delete/72067
Reject -- https://master.php.net/note/reject/72067
Search -- https://master.php.net/manage/user-notes.php