note 72067 rejected from function.json-decode by bjori

From: Date: Mon, 01 Jan 2007 02:23:05 +0000
Subject: note 72067 rejected from function.json-decode by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-121153@lists.php.net to get a copy of this message
Note Submitter: pmeserve at hostmysite dot com ---- 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

« previous php.notes (#121153) next »