{"id":49160,"date":"2024-12-02T09:58:43","date_gmt":"2024-12-02T01:58:43","guid":{"rendered":"https:\/\/fwq.ai\/blog\/49160\/"},"modified":"2024-12-02T09:58:43","modified_gmt":"2024-12-02T01:58:43","slug":"php-json_encode-%e7%bc%96%e7%a0%81%e4%b8%ad%e6%96%87%e5%87%ba%e7%8e%b0%e4%b9%b1%e7%a0%81%ef%bc%8c%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/49160\/","title":{"rendered":"PHP json_encode() \u7f16\u7801\u4e2d\u6587\u51fa\u73b0\u4e71\u7801\uff0c\u5982\u4f55\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP json_encode() \u7f16\u7801\u4e2d\u6587\u51fa\u73b0\u4e71\u7801\uff0c\u5982\u4f55\u89e3\u51b3\uff1f<\/h1>\n<p>\u5c0f\u4f19\u4f34\u4eec\u6709\u6ca1\u6709\u89c9\u5f97\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u5f88\u6709\u610f\u601d\uff1f\u6709\u610f\u601d\u5c31\u5bf9\u4e86\uff01\u4eca\u5929\u5c31\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPHP json_encode() \u7f16\u7801\u4e2d\u6587\u51fa\u73b0\u4e71\u7801\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u300b<\/span>\uff0c\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u5728\u5b66\u4e60\u4e2d\u5bf9\u5176\u4e2d\u90e8\u5206\u77e5\u8bc6\u70b9\u6709\u7591\u95ee\uff0c\u6216\u8bb8\u770b\u4e86\u672c\u6587\u5c31\u80fd\u5e2e\u5230\u4f60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241113\/173148845267346ac4b6742.jpg\" class=\"aligncenter\" title=\"PHP json_encode() \u7f16\u7801\u4e2d\u6587\u51fa\u73b0\u4e71\u7801\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" alt=\"PHP json_encode() \u7f16\u7801\u4e2d\u6587\u51fa\u73b0\u4e71\u7801\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>json \u7f16\u7801\u4e2d\u7684\u4e2d\u6587\u4e71\u7801\u95ee\u9898<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 php \u7684 json_encode() \u51fd\u6570\u5c06\u4e2d\u6587\u6570\u636e\u7f16\u7801\u4e3a json \u65f6\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0\u4e2d\u6587\u4e71\u7801\u7684\u60c5\u51b5\u3002<\/p>\n<p>\u5728\u60a8\u63d0\u4f9b\u7684\u4ee3\u7801\u4e2d\uff0c$users \u6570\u7ec4\u4e2d\u5305\u542b\u4e86\u4ee5\u4e0b\u6570\u636e\uff1a<\/p>\n<pre>\"name\": \"\u6768\"<\/pre>\n<p>\u7f16\u7801\u540e\u7684 json \u5b57\u7b26\u4e32\u4e2d\uff0c&#8221;name&#8221; \u7684\u503c\u663e\u793a\u4e3a &#8220;u6211&#8243;\u3002\u8fd9\u662f\u56e0\u4e3a php \u9ed8\u8ba4\u4f7f\u7528 utf-8 \u7f16\u7801\uff0c\u800c utf-8 \u7f16\u7801\u4e2d\u6587\u65f6\uff0c\u4f1a\u4f7f\u7528 unicode \u7801\u70b9\u3002u6211 \u5c31\u662f\u4e2d\u6587\u5b57\u7b26 &#8220;\u6768&#8221; \u7684 unicode \u7801\u70b9\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u663e\u793a\u4e3a\u4e71\u7801\u7684\u539f\u56e0\u662f\u56e0\u4e3a\u60a8\u5728\u67e5\u770b json \u5b57\u7b26\u4e32\u65f6\u6ca1\u6709\u6b63\u786e\u89e3\u7801 unicode \u7801\u70b9\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>\u8981\u907f\u514d\u6b64\u95ee\u9898\uff0c\u53ef\u4ee5\u5728\u4ee5\u4e0b\u6b65\u9aa4\u4e2d\u89e3\u51b3\uff1a<\/p>\n<ul>\n<li>\u786e\u4fdd\u60a8\u7684 web \u670d\u52a1\u5668\u3001\u6570\u636e\u5e93\u548c php \u6587\u4ef6\u5747\u4f7f\u7528 utf-8 \u7f16\u7801\u3002<\/li>\n<li>\u5728 php \u6587\u4ef6\u4e2d\u663e\u5f0f\u8bbe\u7f6e json \u5934\u90e8 content-type: application\/json; charset=utf-8\u3002<\/li>\n<li>\u5728\u89e3\u6790 json \u5b57\u7b26\u4e32\u65f6\uff0c\u4f7f\u7528\u652f\u6301 unicode \u89e3\u7801\u7684\u51fd\u6570\u6216\u5e93\uff0c\u4f8b\u5982 php \u7684 json_decode() \u51fd\u6570\u6216 javascript \u7684 json.parse() \u65b9\u6cd5\u3002<\/li>\n<\/ul>\n<p>\u4eca\u5929\u5173\u4e8e\u300aPHP json_encode() \u7f16\u7801\u4e2d\u6587\u51fa\u73b0\u4e71\u7801\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u300b\u7684\u5185\u5bb9\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\uff0c\u5982\u679c\u6709\u4ec0\u4e48\u7591\u95ee\u6216\u8005\u5efa\u8bae\uff0c\u53ef\u4ee5\u5728\u7c73\u4e91\u516c\u4f17\u53f7\u4e0b\u591a\u591a\u56de\u590d\u4ea4\u6d41\uff1b\u6587\u4e2d\u82e5\u6709\u4e0d\u6b63\u4e4b\u5904\uff0c\u4e5f\u5e0c\u671b\u56de\u590d\u7559\u8a00\u4ee5\u544a\u77e5\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP json_encode() \u7f16\u7801\u4e2d\u6587\u51fa\u73b0\u4e71\u7801\uff0c\u5982\u4f55\u89e3\u51b3\uff1f \u5c0f\u4f19\u4f34\u4eec\u6709\u6ca1\u6709\u89c9\u5f97\u5b66\u4e60\u6587\u7ae0\u5f88\u6709\u610f\u601d\uff1f\u6709\u610f\u601d\u5c31\u5bf9\u4e86\uff01\u4eca\u5929\u5c31\u7ed9\u5927\u5bb6\u5e26\u6765\u300aPHP json_encode() \u7f16\u7801\u4e2d\u6587\u51fa\u73b0\u4e71\u7801\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u300b\uff0c\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230\uff0c\u82e5\u662f\u5728\u5b66\u4e60\u4e2d\u5bf9\u5176\u4e2d\u90e8\u5206\u77e5\u8bc6\u70b9\u6709\u7591\u95ee\uff0c\u6216\u8bb8\u770b\u4e86\u672c\u6587\u5c31\u80fd\u5e2e\u5230\u4f60\uff01 json \u7f16\u7801\u4e2d\u7684\u4e2d\u6587\u4e71\u7801\u95ee\u9898 \u5728\u4f7f\u7528 php \u7684 json_encode() \u51fd\u6570\u5c06\u4e2d\u6587\u6570\u636e\u7f16\u7801\u4e3a json \u65f6\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0\u4e2d\u6587\u4e71\u7801\u7684\u60c5\u51b5\u3002 \u5728\u60a8\u63d0\u4f9b\u7684\u4ee3\u7801\u4e2d\uff0c$users \u6570\u7ec4\u4e2d\u5305\u542b\u4e86\u4ee5\u4e0b\u6570\u636e\uff1a &#8220;name&#8221;: &#8220;\u6768&#8221; \u7f16\u7801\u540e\u7684 json \u5b57\u7b26\u4e32\u4e2d\uff0c&#8221;name&#8221; \u7684\u503c\u663e\u793a\u4e3a &#8220;u6211&#8243;\u3002\u8fd9\u662f\u56e0\u4e3a php \u9ed8\u8ba4\u4f7f\u7528 utf-8 \u7f16\u7801\uff0c\u800c utf-8 \u7f16\u7801\u4e2d\u6587\u65f6\uff0c\u4f1a\u4f7f\u7528 unicode \u7801\u70b9\u3002u6211 \u5c31\u662f\u4e2d\u6587\u5b57\u7b26 &#8220;\u6768&#8221; \u7684 unicode \u7801\u70b9\u3002 \u56e0\u6b64\uff0c\u663e\u793a\u4e3a\u4e71\u7801\u7684\u539f\u56e0\u662f\u56e0\u4e3a\u60a8\u5728\u67e5\u770b json \u5b57\u7b26\u4e32\u65f6\u6ca1\u6709\u6b63\u786e\u89e3\u7801 unicode \u7801\u70b9\u3002 \u89e3\u51b3\u65b9\u6cd5\uff1a \u8981\u907f\u514d\u6b64\u95ee\u9898\uff0c\u53ef\u4ee5\u5728\u4ee5\u4e0b\u6b65\u9aa4\u4e2d\u89e3\u51b3\uff1a \u786e\u4fdd\u60a8\u7684 web \u670d\u52a1\u5668\u3001\u6570\u636e\u5e93\u548c php \u6587\u4ef6\u5747\u4f7f\u7528 utf-8 \u7f16\u7801\u3002 \u5728 php \u6587\u4ef6\u4e2d\u663e\u5f0f\u8bbe\u7f6e json [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-49160","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49160","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=49160"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49160\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=49160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=49160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=49160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}