{"id":48746,"date":"2024-12-02T15:49:50","date_gmt":"2024-12-02T07:49:50","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48746\/"},"modified":"2024-12-02T15:49:50","modified_gmt":"2024-12-02T07:49:50","slug":"php-json-%e7%bc%96%e7%a0%81%e5%90%8e%ef%bc%8c%e5%8f%8d%e6%96%9c%e6%9d%a0%e8%a2%ab%e6%9b%bf%e6%8d%a2%e4%b8%ba-%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48746\/","title":{"rendered":"PHP JSON \u7f16\u7801\u540e\uff0c\u53cd\u659c\u6760\u88ab\u66ff\u6362\u4e3a \\\\\/ \u5982\u4f55\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP JSON \u7f16\u7801\u540e\uff0c\u53cd\u659c\u6760\u88ab\u66ff\u6362\u4e3a \\\\\/ \u5982\u4f55\u89e3\u51b3\uff1f<\/h1>\n<p>\u6765\u5230\u7c73\u4e91\u7684\u5927\u5bb6\uff0c\u76f8\u4fe1\u90fd\u662f\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5e0c\u671b\u5728\u8fd9\u91cc\u5b66\u4e60\u6587\u7ae0\u76f8\u5173\u7f16\u7a0b\u77e5\u8bc6\u3002\u4e0b\u9762\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u5e26\u5927\u5bb6\u804a\u804a\u300aPHP JSON \u7f16\u7801\u540e\uff0c\u53cd\u659c\u6760\u88ab\u66ff\u6362\u4e3a \\\\\/ \u5982\u4f55\u89e3\u51b3\uff1f\u300b\uff0c\u4ecb\u7ecd\u4e00\u4e0b\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\/20241030\/1730295038672234fe66b46.jpg\" class=\"aligncenter\" title=\"PHP JSON \u7f16\u7801\u540e\uff0c\u53cd\u659c\u6760\u88ab\u66ff\u6362\u4e3a \\\\\/ \u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" alt=\"PHP JSON \u7f16\u7801\u540e\uff0c\u53cd\u659c\u6760\u88ab\u66ff\u6362\u4e3a \\\\\/ \u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>php json \u7f16\u7801\u540e\uff0c\u53cd\u659c\u6760\u66ff\u6362\u95ee\u9898<\/strong><\/p>\n<p>\u5728 php \u4e2d\uff0c\u4f7f\u7528 json_encode \u7f16\u7801\u5b57\u7b26\u4e32\u65f6\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0\u53cd\u659c\u6760\u88ab\u66ff\u6362\u4e3a \/ \u7684\u95ee\u9898\u3002\u672c\u6587\u5c06\u9488\u5bf9\u8be5\u95ee\u9898\u63d0\u4f9b\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<p><strong>\u95ee\u9898\u63cf\u8ff0<\/strong><\/p>\n<p>\u4ee5\u4e0b\u4ee3\u7801\u7528\u4e8e\u67e5\u8be2\u6570\u636e\u5e93\u5e76\u5c06\u5176\u7ed3\u679c\u7f16\u7801\u4e3a json\uff1a<\/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('goodid' =&gt; $row['id'], 'goodname' =&gt; $row['name'], 'goodprice' =&gt; $row['price'], 'memo' =&gt; $row['memo'], 'image' =&gt; $image, 'companyid' =&gt; $row['companyid'], 'companyname' =&gt; $row['company'], 'companyadd' =&gt; $row['address'], 'companyphone' =&gt; $row['phone']);\n    array_push($arr, $tmp);\n}\nmysql_close($con);\nreturn json_encode($arr);<\/pre>\n<p>\u5176\u4e2d\uff0c$row[&#8216;image&#8217;] \u5b58\u50a8\u7684\u662f\u56fe\u7247\u5730\u5740\uff0c\u4f8b\u5982 http:\/\/www.baidu.com\/a.jpg\u3002\u4f46\u662f\uff0c\u8fd4\u56de\u7684 json \u4e2d\uff0c\u53cd\u659c\u6760 \/ \u5168\u90e8\u53d8\u6210\u4e86 \/\uff0c\u5bfc\u81f4\u65e0\u6cd5\u6b63\u5e38\u89e3\u6790\u3002<\/p>\n<pre>[\/{\"goodid\":\"1\",\"goodname\":\"\u5de7\u4e50\u5179\",\"goodprice\":\"2\",\"memo\":\"haochi \",\"image\":\"images\\\/panda.jpg\",\"companyid\":\"1\",\"companyname\":\"\u67da\u5b50\u5c0f\u5e97\",\"companyadd\":\"\u6df1\u5733\",\"companyphone\":\"05341255\"}]<\/pre>\n<p><strong>\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528 str_replace \u51fd\u6570\u66ff\u6362\u53cd\u659c\u6760\uff1a<\/p>\n<pre>$array = str_replace(\"\\\\\/\", \"\/\", json_encode($arr));<\/pre>\n<p>\u8fd9\u6837\uff0c\u8fd4\u56de\u7684 json \u4e2d\u53cd\u659c\u6760\u5c06\u6062\u590d\u6b63\u5e38\u3002<\/p>\n<pre>[{\"goodID\":\"1\",\"goodName\":\"\u5de7\u4e50\u5179\",\"goodPrice\":\"2\",\"memo\":\"haochi \",\"image\":\"images\/panda.jpg\",\"companyID\":\"1\",\"companyName\":\"\u67da\u5b50\u5c0f\u5e97\",\"companyAdd\":\"\u6df1\u5733\",\"companyPhone\":\"05341255\"}]<\/pre>\n<p>\u6587\u4e2d\u5173\u4e8e\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300aPHP JSON \u7f16\u7801\u540e\uff0c\u53cd\u659c\u6760\u88ab\u66ff\u6362\u4e3a \\\\\/ \u5982\u4f55\u89e3\u51b3\uff1f\u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP JSON \u7f16\u7801\u540e\uff0c\u53cd\u659c\u6760\u88ab\u66ff\u6362\u4e3a \\\\\/ \u5982\u4f55\u89e3\u51b3\uff1f \u6765\u5230\u7c73\u4e91\u7684\u5927\u5bb6\uff0c\u76f8\u4fe1\u90fd\u662f\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5e0c\u671b\u5728\u8fd9\u91cc\u5b66\u4e60\u6587\u7ae0\u76f8\u5173\u7f16\u7a0b\u77e5\u8bc6\u3002\u4e0b\u9762\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u5e26\u5927\u5bb6\u804a\u804a\u300aPHP JSON \u7f16\u7801\u540e\uff0c\u53cd\u659c\u6760\u88ab\u66ff\u6362\u4e3a \\\\\/ \u5982\u4f55\u89e3\u51b3\uff1f\u300b\uff0c\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01 php json \u7f16\u7801\u540e\uff0c\u53cd\u659c\u6760\u66ff\u6362\u95ee\u9898 \u5728 php \u4e2d\uff0c\u4f7f\u7528 json_encode \u7f16\u7801\u5b57\u7b26\u4e32\u65f6\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0\u53cd\u659c\u6760\u88ab\u66ff\u6362\u4e3a \/ \u7684\u95ee\u9898\u3002\u672c\u6587\u5c06\u9488\u5bf9\u8be5\u95ee\u9898\u63d0\u4f9b\u89e3\u51b3\u65b9\u6848\u3002 \u95ee\u9898\u63cf\u8ff0 \u4ee5\u4e0b\u4ee3\u7801\u7528\u4e8e\u67e5\u8be2\u6570\u636e\u5e93\u5e76\u5c06\u5176\u7ed3\u679c\u7f16\u7801\u4e3a json\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; $row[&#8216;id&#8217;], &#8216;goodname&#8217; [&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-48746","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48746","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=48746"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48746\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48746"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48746"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48746"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}