代码示例:(标识:demo_php_json_encode)
<!doctype html>
<html>

<body>
<?php
$myObj->name = "Bill Gates";
$myObj->age = 62;
$myObj->city = "Seattle";

$myJSON = json_encode($myObj);

echo $myJSON;
?>
</body>
</html>
运行结果: