Gottlieb NotschnabelChris Barnhill提出了一个问题:PHP json_encode encoding numbers as strings,或许与您遇到的问题类似。
回答者Pascal MARTIN给出了该问题的处理方式:
I've done a very quick test :
$a = array(
'id' => 152,
'another' => 'test',
'ananother' => 456,
);
$json = json_encode($a);
echo $json;
This seems to be like what you describe, if I'm not mistaken ?
And I'm getting as output :
{"id":152,"another":"test","ananother":456}
So, in this case, the integers have not been converted to string.
Still, this might be dependant of the version of PHP we are using : there have been a couple of json_encode related bugs corrected, depending on the version of PHP...
This test has been made with PHP 5.2.6 ; I'm getting the same thing with PHP 5.2.9 and 5.3.0 ; I don't have another 5.2.x version to test with, though :-(
Which version of PHP are you using ? Or is your test-case more complex than the example you posted ?
Maybe Bug #38680 could interest you too, btw ?
希望本文对你有帮助,欢迎支持JavaScript中文网