json_encode序列化 ?php$name = '你好';echo json_encode($name) . PHP_EOL;// \u4f60\u597decho json_encode($name, JSON_UNESCAPED_UNICODE) . PHP_EOL;// 你好 json_decode反序列化 ?php$name = '{name: 张翼德}';// echo json_decode($name
json_encode序列化
<?php
$name = '你好';
echo json_encode($name) . PHP_EOL;
// "\u4f60\u597d"
echo json_encode($name, JSON_UNESCAPED_UNICODE) . PHP_EOL;
// "你好"
json_decode反序列化
<?php
$name = '{"name": "张翼德"}';
// echo json_decode($name) . PHP_EOL;
// PHP Fatal error: Uncaught Error: Object of class stdClass could not be converted to string
var_dump(json_decode($name, true)) . PHP_EOL;
// array(1) {
// ["name"]=> string(9) "张翼德"
// }
参考
- PHP:Cannot use object of type stdClass as array
- PHP:json_encode转换成json空列表和空对象