1、直接用(object)$arr 即可解决
$result = array("arr1" => (object)array(),
"arr2" => array()
);
echo json_encode($result );// {"arr1":{}, "arr2":[]}
2、还有一个办法就是给json_encode()添加参数JSON_FORCE_OBJECT,如下
json_encode($result ,JSON_FORCE_OBJECT)得到的是{
"arr1": {},
"arr2": {}
}
网友回复