{"id":48613,"date":"2024-12-02T12:16:13","date_gmt":"2024-12-02T04:16:13","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48613\/"},"modified":"2024-12-02T12:16:13","modified_gmt":"2024-12-02T04:16:13","slug":"php-json-%e8%bd%ac%e7%a0%81%e4%b8%ad%e6%96%87%e4%b9%b1%e7%a0%81%ef%bc%9a%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3-json_encode-%e5%87%bd%e6%95%b0%e8%be%93%e5%87%ba%e4%b9%b1%e7%a0%81%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48613\/","title":{"rendered":"PHP JSON \u8f6c\u7801\u4e2d\u6587\u4e71\u7801\uff1a\u5982\u4f55\u89e3\u51b3 json_encode \u51fd\u6570\u8f93\u51fa\u4e71\u7801\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP JSON \u8f6c\u7801\u4e2d\u6587\u4e71\u7801\uff1a\u5982\u4f55\u89e3\u51b3 json_encode \u51fd\u6570\u8f93\u51fa\u4e71\u7801\uff1f<\/h1>\n<p>\u5728IT\u884c\u4e1a\u8fd9\u4e2a\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u5f88\u5feb\u7684\u884c\u4e1a\uff0c\u53ea\u6709\u4e0d\u505c\u6b62\u7684\u5b66\u4e60\uff0c\u624d\u4e0d\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u5982\u679c\u4f60\u662f\u6587\u7ae0\u5b66\u4e60\u8005\uff0c\u90a3\u4e48\u672c\u6587\u300aPHP JSON \u8f6c\u7801\u4e2d\u6587\u4e71\u7801\uff1a\u5982\u4f55\u89e3\u51b3 json_encode \u51fd\u6570\u8f93\u51fa\u4e71\u7801\uff1f\u300b\u5c31\u5f88\u9002\u5408\u4f60\uff01\u672c\u7bc7\u5185\u5bb9\u4e3b\u8981\u5305\u62ec##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241028\/1730122081671f91611eb21.jpg\" class=\"aligncenter\" title=\"PHP JSON \u8f6c\u7801\u4e2d\u6587\u4e71\u7801\uff1a\u5982\u4f55\u89e3\u51b3 json_encode \u51fd\u6570\u8f93\u51fa\u4e71\u7801\uff1f\u63d2\u56fe\" alt=\"PHP JSON \u8f6c\u7801\u4e2d\u6587\u4e71\u7801\uff1a\u5982\u4f55\u89e3\u51b3 json_encode \u51fd\u6570\u8f93\u51fa\u4e71\u7801\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>json \u8f6c\u7801\u4e71\u7801\u95ee\u9898<\/strong><\/p>\n<p>php \u4ee3\u7801\u4e2d\u4f7f\u7528 json_encode \u51fd\u6570\u8f93\u51fa json \u5b57\u7b26\u4e32\u65f6\uff0c\u51fa\u73b0\u4e2d\u6587\u5185\u5bb9\u4e71\u7801\u3002\u5982\u4ee5\u4e0b\u793a\u4f8b\u4ee3\u7801\u6240\u793a\uff1a<\/p>\n<pre>\/\/ php \u9875\u9762\u4ee3\u7801\nif ($result1) {\n    $users = array();\n    $i = 0;\n    while ($row = mysql_fetch_array($result1, mysql_assoc)) {\n        $users[$i] = $row;\n        $i++;\n    }\n    echo json_encode(array(\"result\" =&gt; \"success\", \"countall\" =&gt; $roa[0], \"data\" =&gt; $users));\n} else {\n    echo json_encode(array(\"result\" =&gt; \"fail\"));\n}<\/pre>\n<p>\u8f93\u51fa\u7684 json \u5b57\u7b26\u4e32\u4e2d\uff0c\u4e2d\u6587\u201c\u674e\u56db\u201d\u4e71\u7801\u4e3a\uff1a\u201cu53bb\u201d\u3002<\/p>\n<p><strong>\u9519\u8bef\u89e3\u6790<\/strong><\/p>\n<p>\u4ee3\u7801\u4e2d\u4f7f\u7528\u7684 json_encode \u51fd\u6570\u9ed8\u8ba4\u5c06\u5b57\u7b26\u4e32\u8f6c\u7801\u4e3a unicode \u7f16\u7801\u683c\u5f0f\uff0c\u800c\u4e0d\u662f utf-8\u3002\u4e2d\u6587\u5728 unicode \u7f16\u7801\u4e2d\u7684\u8868\u793a\u5f62\u5f0f\u4e0e utf-8 \u4e0d\u540c\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u8981\u89e3\u51b3\u4e71\u7801\u95ee\u9898\uff0c\u9700\u8981\u5728\u4f7f\u7528 json_encode \u51fd\u6570\u65f6\u6307\u5b9a utf-8 \u7f16\u7801\u9009\u9879\uff1a<\/p>\n<pre>\/\/ PHP \u9875\u9762\u4ee3\u7801\nif ($result1) {\n    $users = array();\n    $i = 0;\n    while ($row = mysql_fetch_array($result1, MYSQL_ASSOC)) {\n        $users[$i] = $row;\n        $i++;\n    }\n    echo json_encode(array(\"result\" =&gt; \"success\", \"countAll\" =&gt; $roa[0], \"data\" =&gt; $users), JSON_UNESCAPED_UNICODE);\n} else {\n    echo json_encode(array(\"result\" =&gt; \"fail\"));\n}<\/pre>\n<p>json_unescaped_unicode \u9009\u9879\u6307\u793a json_encode \u51fd\u6570\u5c06 unicode \u5b57\u7b26\u4f5c\u4e3a\u539f\u59cb unicode \u7801\u70b9\u8f93\u51fa\uff0c\u800c\u4e0d\u662f\u8f6c\u4e49\u5e8f\u5217\u3002\u8fd9\u6837\u5c31\u4e0d\u4f1a\u51fa\u73b0\u4e71\u7801\u95ee\u9898\u4e86\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\u7c73\u4e91\uff01\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP JSON \u8f6c\u7801\u4e2d\u6587\u4e71\u7801\uff1a\u5982\u4f55\u89e3\u51b3 json_encode \u51fd\u6570\u8f93\u51fa\u4e71\u7801\uff1f \u5728IT\u884c\u4e1a\u8fd9\u4e2a\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u5f88\u5feb\u7684\u884c\u4e1a\uff0c\u53ea\u6709\u4e0d\u505c\u6b62\u7684\u5b66\u4e60\uff0c\u624d\u4e0d\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u5982\u679c\u4f60\u662f\u6587\u7ae0\u5b66\u4e60\u8005\uff0c\u90a3\u4e48\u672c\u6587\u300aPHP JSON \u8f6c\u7801\u4e2d\u6587\u4e71\u7801\uff1a\u5982\u4f55\u89e3\u51b3 json_encode \u51fd\u6570\u8f93\u51fa\u4e71\u7801\uff1f\u300b\u5c31\u5f88\u9002\u5408\u4f60\uff01\u672c\u7bc7\u5185\u5bb9\u4e3b\u8981\u5305\u62ec##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01 json \u8f6c\u7801\u4e71\u7801\u95ee\u9898 php \u4ee3\u7801\u4e2d\u4f7f\u7528 json_encode \u51fd\u6570\u8f93\u51fa json \u5b57\u7b26\u4e32\u65f6\uff0c\u51fa\u73b0\u4e2d\u6587\u5185\u5bb9\u4e71\u7801\u3002\u5982\u4ee5\u4e0b\u793a\u4f8b\u4ee3\u7801\u6240\u793a\uff1a \/\/ php \u9875\u9762\u4ee3\u7801 if ($result1) { $users = array(); $i = 0; while ($row = mysql_fetch_array($result1, mysql_assoc)) { $users[$i] = $row; $i++; } echo json_encode(array(&#8220;result&#8221; =&gt; &#8220;success&#8221;, &#8220;countall&#8221; =&gt; $roa[0], &#8220;data&#8221; =&gt; $users)); } else { echo [&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-48613","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48613","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=48613"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48613\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48613"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48613"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48613"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}