जाहिर है, अनंत और NaN JSON विनिर्देशन के एक हिस्से नहीं हैं, इसलिए इस PHP कोड:PHP: जेएसओएन को अनंत या NaN संख्या कैसे एन्कोड करें?
$numbers = array();
$numbers ['positive_infinity'] = +INF;
$numbers ['negative_infinity'] = -INF;
$numbers ['not_a_number'] = NAN;
$array_print = print_r ($numbers, true);
$array_json = json_encode ($numbers);
echo "\nprint_r(): $array_print";
echo "\njson_encode(): $array_json";
इस उत्पादन: मेरे अपने लेखन के बिना
PHP Warning: json_encode(): double INF does not conform to the JSON spec, encoded as 0 in /home/septi/test.php on line 8
PHP Warning: json_encode(): double -INF does not conform to the JSON spec, encoded as 0 in /home/septi/test.php on line 8
PHP Warning: json_encode(): double NAN does not conform to the JSON spec, encoded as 0 in /home/septi/test.php on line 8
print_r(): Array
(
[positive_infinity] => INF
[negative_infinity] => -INF
[not_a_number] => NAN
)
json_encode(): {"positive_infinity":0,"negative_infinity":0,"not_a_number":0}
वहाँ किसी भी तरह से सही ढंग से इन नंबरों एन्कोड करने के लिए है json_encode()
समारोह? शायद कुछ कामकाज?
+1 कल्पना का हवाला देते हुए और शाब्दिक उल्लेख के लिए। हालांकि, दूसरे उत्तर को स्वीकार करते हुए, क्योंकि यह उन्हें वापस संख्याओं में बदलने का तरीका सुझाता है। – Septagram