Php returns data as an interface. php returns data as an interface.
{"Status": "0", "message": "\ u9a8c \ u8bc1 \ u7801 \ u9519 \ u8bef", "data ": {"a": "1"}, where $ result is an array in data. if $ result is empty, $ result = array (); output {"status ": "0", "message": "\ u9a8c \ u8bc1 \ u7801 \ u9519 \ u8bef", "data": []}. the returned data is in brackets, how to replace data with braces: {"status": "0", "message": "\ u9a8c \ u8bc1 \ u7801 \ u9519 \ u8bef", "data ": what about the form?
Reply to discussion (solution)
Generally, it is unnecessary. Otherwise, you have to write it again.
Generally, it is unnecessary. Otherwise, you have to write it again.
No way. The front-end IOS and Android devices are too busy to require this format.
The returned result is as follows:
Echo json_encode ($ array );
You changed it to this.
Echo str_replace ('[]', '{}', json_encode ($ array ));
Use the JSON_FORCE_OBJECT parameter.
0);var_dump(json_encode($a,JSON_FORCE_OBJECT));
string(2) "{}"string(19) "{"0":1,"1":2,"2":3}"string(9) "{"ret":0}"
JSON_FORCE_OBJECT (integer)
Outputs a class (Object) instead of an array from a non-correlated array. This is especially useful when the array is empty and the receiver needs a class (Object. It takes effect from PHP 5.3.0.