下面值是存在数据库的,
{"post":{"categories":"14","id":"177","post_title":"Qiuziti.com","post_keywords":"","post_source":"","siteUrl":"https:\/\/www.qiuziti.com\/","post_excerpt":"\u5728\u7ebf\u8bc6\u522b\u5b57\u4f53","more":{"audio":"","video":"","thumbnail":"portal\/20230822\/c6bb8d78c842b4a282d5c5ad109fe91b.png","template":""},"published_time":"2023-08-22 12:27","post_status":"1"}}
我拿出来用json_decode转成了数组,
array(1) {
["post"] => array(10) {
["categories"] => string(2) "14"
["id"] => string(3) "177"
["post_title"] => string(11) "Qiuziti.com"
["post_keywords"] => string(0) ""
["post_source"] => string(0) ""
["siteUrl"] => string(24) "https://www.qiuziti.com/"
["post_excerpt"] => string(18) "在线识别字体"
["more"] => array(4) {
["audio"] => string(0) ""
["video"] => string(0) ""
["thumbnail"] => string(52) "portal/20230822/c6bb8d78c842b4a282d5c5ad109fe91b.png"
["template"] => string(0) ""
}
["published_time"] => string(16) "2023-08-22 12:27"
["post_status"] => string(1) "1"
}
}
但是数组没办法一下子在前端展示,我想把上面的转成json或字符串,并且转后汉字还是汉字。这怎么实现?
你是说数据库里的 JSON 字符串已经是将 Unicode 转义后存储的了,你现在希望输出给前端的时候不要转义 Unicode?
那你可以先 decode、然后再 encode 一次:
不过这仅仅是字符转义而已,实际上你在页面上直接渲染它,显示出来的就是汉字。就像
\n
显示出来就是换行符一样。所以我不太明白你非得想不转义的意图是什么?