📜  在 php 代码示例中将 stdclass 转换为 json

📅  最后修改于: 2022-03-11 14:53:56.796000             🧑  作者: Mango

代码示例1
$stdClass = new stdClass();
$stdClass->name = "avatar";
$stdClass->age = 31;
$json_data = json_encode ((array) $stdClass);
print_r($json_data); //{"name":"avatar","age":31}