note 113416 added to function.json-encode

From: Date: Tue, 08 Oct 2013 16:27:11 +0000
Subject: note 113416 added to function.json-encode
Groups: php.notes 
Request: Send a blank email to php-notes+get-196498@lists.php.net to get a copy of this message
There is a gotcha that keeps getting me with JSON_NUMERIC_CHECK. At first it seems like the greatest thing in the world if you are encoding data pulled from a db because it turns numeric strings into seemingly appropriate ints or floats. Use with caution. I've been surprised a number of times by "numbers" that really are strings ie really precise lat/long coords. json_encode with the JSON_NUMERIC_CHECK will encode these as floats but the precision of the data is so large that php actually rounds the number off. In this case I had to rework my code so that it didn't use JSON_NUMERIC_CHECK and I manually cast fields as ints or floats as appropriate and skipped my lat/long fields so that they stayed numeric strings. ---- Server IP: 69.147.83.199 Probable Submitter: 68.186.33.182 ---- Manual Page -- http://php.net/manual/en/function.json-encode.php Edit -- https://master.php.net/note/edit/113416 Del: integrated -- https://master.php.net/note/delete/113416/integrated Del: useless -- https://master.php.net/note/delete/113416/useless Del: bad code -- https://master.php.net/note/delete/113416/bad+code Del: spam -- https://master.php.net/note/delete/113416/spam Del: non-english -- https://master.php.net/note/delete/113416/non-english Del: in docs -- https://master.php.net/note/delete/113416/in+docs Del: other reasons-- https://master.php.net/note/delete/113416 Reject -- https://master.php.net/note/reject/113416 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#196498) next »