PHP JSON格式的输出和解析
2022-07-28 15:09:43
163
{{single.collect_count}}

生成JSON格式

<?phpheader(‘content-type:application/json’);$number = array('1','2','3','4','5','6','7','8','9','0');echo json_encode($number); //json_encode对变量进行 JSON 编码?>

JSON格式的解析

<?phpheader(‘content-type:application/json’);$number = array('1','2','3','4','5','6','7','8','9','0');echo json_encode($number); //json_encode对变量进行 JSON 编码echo json_decode($number); //对 JSON 格式的字符串进行解码,转换为 PHP 变量?>

header(‘Content-type:text/json’);
只是http协议中标识出,输出是什么类型的内容。
实际使用中,有时随然此值,不是text/json 浏览器依然可以正常解析成为json格式,只是因为浏览器端,做了json格式内容的自动识别,或者有浏览器插件,做了自动识别。

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}