{"id":49042,"date":"2024-12-02T16:22:04","date_gmt":"2024-12-02T08:22:04","guid":{"rendered":"https:\/\/fwq.ai\/blog\/49042\/"},"modified":"2024-12-02T16:22:04","modified_gmt":"2024-12-02T08:22:04","slug":"php-json-%e7%bc%96%e7%a0%81%e6%97%b6%e6%96%9c%e6%9d%a0%e4%b8%a2%e5%a4%b1%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\/49042\/","title":{"rendered":"PHP JSON \u7f16\u7801\u65f6\u659c\u6760\u4e22\u5931\uff0c\u5982\u4f55\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP JSON \u7f16\u7801\u65f6\u659c\u6760\u4e22\u5931\uff0c\u5982\u4f55\u89e3\u51b3\uff1f<\/h1>\n<p>\u54c8\u55bd\uff01\u4eca\u5929\u5fc3\u8840\u6765\u6f6e\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPHP JSON \u7f16\u7801\u65f6\u659c\u6760\u4e22\u5931\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u300b<\/span>\uff0c\u60f3\u5fc5\u5927\u5bb6\u5e94\u8be5\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u90fd\u4e0d\u964c\u751f\u5427\uff0c\u90a3\u4e48\u9605\u8bfb\u672c\u6587\u5c31\u90fd\u4e0d\u4f1a\u5f88\u56f0\u96be\uff0c\u4ee5\u4e0b\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u4f60\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\uff0c\u5343\u4e07\u522b\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u4f60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241107\/1730978669672ca36dd781b.jpg\" class=\"aligncenter\" title=\"PHP JSON \u7f16\u7801\u65f6\u659c\u6760\u4e22\u5931\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" alt=\"PHP JSON \u7f16\u7801\u65f6\u659c\u6760\u4e22\u5931\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>json \u7f16\u7801\u540e\u659c\u6760\u4e22\u5931\u95ee\u9898<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong><\/p>\n<p>\u6267\u884c php \u4ee3\u7801\u540e\uff0c\u6570\u636e\u5e93\u4e2d\u7684\u56fe\u7247\u5730\u5740\u4e2d\u7684\u659c\u6760 \/ \u88ab\u66ff\u6362\u4e3a \/\u3002\u4f8b\u5982\uff0c&#8221;http:\/\/www.baidu.com\/a.jpg&#8221; \u53d8\u6210\u4e86 &#8220;http:\/\/www.baidu.com\/a.jpg&#8221;\u3002<\/p>\n<p><strong>\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>$result = mysql_query(\"select g.*, u.id as companyid, u.company, u.address, u.phone from tblgood g join tbluser u on g.companyid = u.id where g.code=$code\");\nwhile ($row = mysql_fetch_array($result)) {\n    $image = iconv(\"gbk\", \"utf-8\/\/ignore\", $row['image']);\n    $tmp = array(\n        'goodid' =&gt; $row['id'],\n        'goodname' =&gt; $row['name'],\n        'goodprice' =&gt; $row['price'],\n        'memo' =&gt; $row['memo'],\n        'image' =&gt; $image,\n        'companyid' =&gt; $row['companyid'],\n        'companyname' =&gt; $row['company'],\n        'companyadd' =&gt; $row['address'],\n        'companyphone' =&gt; $row['phone']\n    );\n    array_push($arr, $tmp);\n}\nmysql_close($con);\n\/\/ \u8fd4\u56de\u7684\u95ee\u9898 json \u6570\u636e\nreturn json_encode($arr);<\/pre>\n<p><strong>\u539f\u56e0\uff1a<\/strong><\/p>\n<p>json_encode \u51fd\u6570\u5728\u7f16\u7801\u65f6\u5c06\u659c\u6760\u89c6\u4e3a\u8f6c\u4e49\u5b57\u7b26\u3002\u56e0\u6b64\uff0c\u6570\u636e\u5e93\u4e2d\u7684\u659c\u6760\u5728\u7f16\u7801\u540e\u5b9e\u9645\u4e0a\u53d8\u6210\u4e86\u8f6c\u4e49\u5e8f\u5217 `\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u5728\u7f16\u7801 json \u6570\u636e\u4e4b\u524d\uff0c\u53ef\u4ee5\u4f7f\u7528 str_replace \u51fd\u6570\u5c06\u659c\u6760\u66ff\u6362\u4e3a\u672c\u8eab\u3002<\/p>\n<pre>\/\/ \u66ff\u6362\u659c\u6760\n$array = str_replace(\"\\\\\/\", \"\/\", json_encode($arr));\n\/\/ \u8fd4\u56de\u4fee\u6b63\u540e\u7684 JSON \u6570\u636e\nreturn $array;<\/pre>\n<p>\u4eca\u5929\u5173\u4e8e\u300aPHP JSON \u7f16\u7801\u65f6\u659c\u6760\u4e22\u5931\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u300b\u7684\u5185\u5bb9\u5c31\u4ecb\u7ecd\u5230\u8fd9\u91cc\u4e86\uff0c\u662f\u4e0d\u662f\u5b66\u8d77\u6765\u4e00\u76ee\u4e86\u7136\uff01\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u5185\u5bb9\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP JSON \u7f16\u7801\u65f6\u659c\u6760\u4e22\u5931\uff0c\u5982\u4f55\u89e3\u51b3\uff1f \u54c8\u55bd\uff01\u4eca\u5929\u5fc3\u8840\u6765\u6f6e\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86\u300aPHP JSON \u7f16\u7801\u65f6\u659c\u6760\u4e22\u5931\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u300b\uff0c\u60f3\u5fc5\u5927\u5bb6\u5e94\u8be5\u5bf9\u6587\u7ae0\u90fd\u4e0d\u964c\u751f\u5427\uff0c\u90a3\u4e48\u9605\u8bfb\u672c\u6587\u5c31\u90fd\u4e0d\u4f1a\u5f88\u56f0\u96be\uff0c\u4ee5\u4e0b\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230\uff0c\u82e5\u662f\u4f60\u6b63\u5728\u5b66\u4e60\u6587\u7ae0\uff0c\u5343\u4e07\u522b\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u4f60\uff01 json \u7f16\u7801\u540e\u659c\u6760\u4e22\u5931\u95ee\u9898 \u95ee\u9898\uff1a \u6267\u884c php \u4ee3\u7801\u540e\uff0c\u6570\u636e\u5e93\u4e2d\u7684\u56fe\u7247\u5730\u5740\u4e2d\u7684\u659c\u6760 \/ \u88ab\u66ff\u6362\u4e3a \/\u3002\u4f8b\u5982\uff0c&#8221;http:\/\/www.baidu.com\/a.jpg&#8221; \u53d8\u6210\u4e86 &#8220;http:\/\/www.baidu.com\/a.jpg&#8221;\u3002 \u4ee3\u7801\uff1a $result = mysql_query(&#8220;select g.*, u.id as companyid, u.company, u.address, u.phone from tblgood g join tbluser u on g.companyid = u.id where g.code=$code&#8221;); while ($row = mysql_fetch_array($result)) { $image = iconv(&#8220;gbk&#8221;, &#8220;utf-8\/\/ignore&#8221;, $row[&#8216;image&#8217;]); $tmp = array( &#8216;goodid&#8217; =&gt; [&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-49042","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49042","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=49042"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49042\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=49042"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=49042"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=49042"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}