简体   繁体   中英

How to generate {0} json string by PHP?

There is a json string and it's

["email",{},"text","xyz@x.y"]

I don't how to generate the '{}' by json_encode($data, JSON_UNESCAPED_SLASHES); I try several sample codes like:

$data = ["email", null, "text", "xyz@x.y"];  // the output is ["email",null,"text","xyz@x.y"]
$data = ["email", "", "text", "xyz@x.y"]; // the output is ["email","","text","xyz@x.y"]
$data = ["email", [], "text", "xyz@x.y"]; // the output is ["email",[],"text","xyz@x.y"]

Does anyone know how to do? Thank you. Regards.

$data = ["email", new stdclass, "text", "xyz@x.y"];

echo json_encode($data);

will output

["email",{},"text","xyz@x.y"]

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM