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) "张翼德" // }
参考