? Secretly tell you that this is a very imprudent will tread on the pit?
The following code (looked very simple, no problem ah, old iron)
$arr Array ( ' 0 ' = ' a ', ' 1 ' = ' B ', ' 2 ' = ' C ', ' 3 ' = ' + ' d '); echo json_encode ($arr);
But the result is
["A", "B", "C", "D"]
The requirement is to return the JSON object, like so
{"0": "A", "1": "B", "2": "C", "3": "D"}
You can do it,you nee add
$arr Array ( ' 0 ' = ' a ', ' 1 ' = ' B ', ' 2 ' = ' C ', ' 3 ' = ' + ' d '); Echo Json_encode ((object)$arr);
Output results
{"0": "A", "1": "B", "2": "C", "3": "D"}
Bingo, take care.
Summary: PHP array =>json array/object, but PHP object =>json object, so if it is responsible for the development of the interface class, it is recommended that json_encode () can be cast first (object).
PHP json_encode () Usage notes, JSON arrays and JSON objects