Answer the question
In order to leave comments, you need to log in
How to set up json_encode?
Data is exported incorrectly to json. The variable stores an array of float numbers. var_dump outputs the following:
2823 =>
array (size=3)
'o' => int 3
'p' => string '58.9' (length=4)
'b' => float 6.6
2824 =>
array (size=3)
'o' => int 3
'p' => string '57.1' (length=4)
'b' => float 6.4
echo json_encode($var)
outputs the following:"2823":{"o":3,"p":"58.9","b":6.600000000000001},"2824":{"o":3,"p":"57.1","b":6.4}
b
is not converted correctly in the first case, although it is correct in the second case. These are only 2 elements from the entire array, but in most cases it is converted crookedly. $.parseJSON($('#forang').text())
2823:Object
b:6.600000000000001
o:3
p:"58.9"
2824:Object
b:6.4
o:3
p:"57.1"
echo json_encode(['a'=>6.6]);
{"a":6.6}
Answer the question
In order to leave comments, you need to log in
Look at the constants the constants php.net/manual/en/json.constants.php
For example: Guarantees that a float value will be converted exactly to a float value...
Either encode base64 before json, although I think there is a constant that is either as a string all will either pass or tell json_encode to mind your own business.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question