Php returns data as an interface. If php returns data as an interface, {status: 0, message: u9a8cu8bc1u7801u9519u8bef, data: {a: 1} is returned }}, $ result is an array in data. if $ result is empty, $ result & nbsp; array (); & nbsp; 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?
------ Solution ----------------------
Generally, it is unnecessary. Otherwise, you have to write it again.
------ Solution ----------------------
The returned result is as follows:
Echo json_encode ($ array );
You changed it to this.
Echo str_replace ('[]', '{}', json_encode ($ array ));
------ Solution ----------------------
Use the JSON_FORCE_OBJECT parameter.
$a=array();
var_dump(json_encode($a,JSON_FORCE_OBJECT));
$a=array(1,2,3);
var_dump(json_encode($a,JSON_FORCE_OBJECT));
$a=array("ret"=>0);
var_dump(json_encode($a,JSON_FORCE_OBJECT));
string(2) "{}"
string(19) "{"0":1,"1":2,"2":3}"
string(9) "{"ret":0}"
------ Solution ----------------------
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.