After using json_decode, php converts numeric objects into scientific notation.
This article describes how to convert a numeric object into a scientific notation after json_decode is used by php. We will share this with you for your reference. The details are as follows:
Problem:
Today, we are engaged in the integration of web games on facebook points. facebook transfers a json-like string to the callball. when these parameters are applied on the php page, a json_decode operation is performed, and long numbers are converted into scientific notation, which is not the result I want.
Solution:
It is difficult to handle the conversion in all aspects:
$obj='{"order_id":213477815351175,"buyer":100001169269154}';$obj=$this->json_decode($obj,TRUE);print_r($obj);
Result:
Array( [order_id] => 2.1347781535118E+14 [buyer] => 1.0000116926915E+14)
Finally, use the built-in function number_format () in php to solve the problem. The effect is as follows:
$obj='{"order_id":213477815351175,"buyer":100001169269154}';$obj=$this->json_decode($obj,TRUE);foreach ($obj as $key=>$val){ $obj[$key]=number_format($val,0,'','');}print_r($obj);
Result:
Array( [order_id] => 213477815351175 [buyer] => 100001169269154)
PS: Here are some useful json online tools for your reference:
Online JSON code verification, validation, beautification, and formatting tools:
Http://tools.jb51.net/code/json
JSON online formatting tool:
Http://tools.jb51.net/code/jsonformat
Online XML/JSON conversion tools:
Http://tools.jb51.net/code/xmljson
Json code online formatting/beautification/compression/editing/conversion tools:
Http://tools.jb51.net/code/jsoncodeformat
C language style/HTML/CSS/json code formatting and beautification tools:
Http://tools.jb51.net/code/ccode_html_css_json