I want to have an empty object in the API response like the one mentioned below:
{
"sample" : {}
}
When I assign $response['sample'] = array(), I get the following response
{
"sample" : []
}
{}表示一个对象,因此您必须使用
$result = ["sample" => new stdclass()];
you must try JSON_FORCE_OBJECT
as second argument while using json_encode
function.
EDIT
$ar = array("sample" => array());
echo json_encode($ar, JSON_FORCE_OBJECT);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.