{"id":35755,"date":"2025-05-06T17:15:54","date_gmt":"2025-05-06T09:15:54","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/35755.html"},"modified":"2025-05-06T17:15:54","modified_gmt":"2025-05-06T09:15:54","slug":"python%e4%b8%ad%e7%9a%84json%e5%ba%93%ef%bc%8c%e8%af%a6%e7%bb%86%e4%bb%8b%e7%bb%8d%e4%b8%8e%e4%bb%a3%e7%a0%81%e7%a4%ba%e4%be%8b","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/35755.html","title":{"rendered":"Python\u4e2d\u7684JSON\u5e93\uff0c\u8be6\u7ec6\u4ecb\u7ecd\u4e0e\u4ee3\u7801\u793a\u4f8b"},"content":{"rendered":"<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"1.%20%E5%89%8D%E8%A8%80-toc\" style=\"margin-left:0px\">1. \u524d\u8a00<\/p>\n<p id=\"2.%20json%20%E5%BA%93%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5-toc\" style=\"margin-left:0px\">2. json \u5e93\u57fa\u672c\u6982\u5ff5<\/p>\n<p id=\"3.%20json%20%E7%9A%84%E9%80%82%E5%BA%94%E5%9C%BA%E6%99%AF-toc\" style=\"margin-left:0px\">3. json \u7684\u9002\u5e94\u573a\u666f<\/p>\n<p id=\"4.%20json%20%E5%BA%93%E7%9A%84%E5%9F%BA%E6%9C%AC%E7%94%A8%E6%B3%95-toc\" style=\"margin-left:0px\">4. json \u5e93\u7684\u57fa\u672c\u7528\u6cd5<\/p>\n<p id=\"4.1%20%E5%AF%BC%20json%E5%85%A5%20%E6%A8%A1%E5%9D%97-toc\" style=\"margin-left:40px\">4.1 \u5bfc json\u5165 \u6a21\u5757<\/p>\n<p id=\"4.2%20%E5%B0%86%20Python%20%E5%AF%B9%E8%B1%A1%E8%BD%AC%E6%8D%A2%E4%B8%BA%20JSON%20%E5%AD%97%E7%AC%A6%E4%B8%B2-toc\" style=\"margin-left:40px\">4.2 \u5c06 Python \u5bf9\u8c61\u8f6c\u6362\u4e3a JSON \u5b57\u7b26\u4e32<\/p>\n<p id=\"4.3%20%E5%B0%86%20JSON%20%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%BD%AC%E6%8D%A2%E4%B8%BA%20Python%20%E5%AF%B9%E8%B1%A1-toc\" style=\"margin-left:40px\">4.3 \u5c06 JSON \u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a Python \u5bf9\u8c61<\/p>\n<p id=\"4.4%20%E5%B0%86%20Python%20%E5%AF%B9%E8%B1%A1%E5%86%99%E5%85%A5%20JSON%20%E6%96%87%E4%BB%B6-toc\" style=\"margin-left:40px\">4.4 \u5c06 Python \u5bf9\u8c61\u5199\u5165 JSON \u6587\u4ef6<\/p>\n<p id=\"4.5%20%E4%BB%8E%20JSON%20%E6%96%87%E4%BB%B6%E8%AF%BB%E5%8F%96%E6%95%B0%E6%8D%AE-toc\" style=\"margin-left:40px\">4.5 \u4ece JSON \u6587\u4ef6\u8bfb\u53d6\u6570\u636e<\/p>\n<p id=\"4.6%20json%20%E7%9A%84%E5%85%B6%E4%BB%96%E6%96%B9%E6%B3%95-toc\" style=\"margin-left:40px\">4.6 json \u7684\u5176\u4ed6\u65b9\u6cd5<\/p>\n<p id=\"5.%20json%20%E5%BA%93%E7%9A%84%E9%AB%98%E7%BA%A7%E7%94%A8%E6%B3%95-toc\" style=\"margin-left:0px\">5. json \u5e93\u7684\u9ad8\u7ea7\u7528\u6cd5<\/p>\n<p id=\"5.1%20%E8%87%AA%E5%AE%9A%E4%B9%89%E5%AF%B9%E8%B1%A1%E7%9A%84%E5%BA%8F%E5%88%97%E5%8C%96%E4%B8%8E%E5%8F%8D%E5%BA%8F%E5%88%97%E5%8C%96%E5%9C%A8-toc\" style=\"margin-left:40px\">5.1 \u81ea\u5b9a\u4e49\u5bf9\u8c61\u7684\u5e8f\u5217\u5316\u4e0e\u53cd\u5e8f\u5217\u5316\u5728<\/p>\n<p id=\"5.2%20%E5%A4%84%E7%90%86%E9%9D%9E%20ASCII%20%E5%AD%97%E7%AC%A6-toc\" style=\"margin-left:40px\">5.2 \u5904\u7406\u975e ASCII \u5b57\u7b26<\/p>\n<p id=\"5.3%20%E4%BD%BF%E7%94%A8%20indent%20%E5%8F%82%E6%95%B0%E7%BE%8E%E5%8C%96%E8%BE%93%E5%87%BA-toc\" style=\"margin-left:40px\">5.3 \u4f7f\u7528 indent \u53c2\u6570\u7f8e\u5316\u8f93\u51fa<\/p>\n<p id=\"6.%20json%20%E5%BA%93%E7%9A%84%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86-toc\" style=\"margin-left:0px\">6. json \u5e93\u7684\u5f02\u5e38\u5904\u7406<\/p>\n<p id=\"6.1%20%E5%B8%B8%E8%A7%81%E7%9A%84%E5%BC%82%E5%B8%B8%E7%B1%BB%E5%9E%8B-toc\" style=\"margin-left:40px\">6.1 \u5e38\u89c1\u7684\u5f02\u5e38\u7c7b\u578b<\/p>\n<p id=\"6.2%20%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86%E7%A4%BA%E4%BE%8B-toc\" style=\"margin-left:40px\">6.2 \u5f02\u5e38\u5904\u7406\u793a\u4f8b<\/p>\n<p id=\"7.%20%E6%80%BB%E7%BB%93-toc\" style=\"margin-left:0px\">7. \u603b\u7ed3<\/p>\n<hr id=\"hr-toc\" \/>\n<h2 id=\"1.%20%E5%89%8D%E8%A8%80\">1. \u524d\u8a00<\/h2>\n<p>\u5728\u6211\u4eec\u65e5\u5e38\u7684 Python \u7f16\u7a0b\u4e2d&#xff0c;\u6570\u636e\u7684\u5b58\u50a8\u4e0e\u4f20\u9012\u662f\u4e0d\u53ef\u907f\u514d\u7684\u4e00\u4e2a\u73af\u8282\u3002\u60f3\u8c61\u4e00\u4e0b&#xff0c;\u6211\u4eec\u5728\u5f00\u53d1\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\u65f6&#xff0c;\u9700\u8981\u5c06\u4e00\u4e9b\u914d\u7f6e\u4fe1\u606f\u5b58\u50a8\u8d77\u6765&#xff0c;\u6216\u8005\u8981\u5c06\u6570\u636e\u53d1\u9001\u5230\u53e6\u4e00\u4e2a\u7cfb\u7edf\u4e2d\u3002\u8fd9\u65f6\u5019&#xff0c;\u6211\u4eec\u5c31\u9700\u8981\u4e00\u79cd\u9ad8\u6548\u3001\u4fbf\u6377\u7684\u65b9\u5f0f\u6765\u5b8c\u6210\u8fd9\u4e2a\u3002\u4efb\u52a1JSON&#xff08;JavaScript Object Notation&#xff09;&#xff0c;\u4f5c\u4e3a\u4e00\u79cd\u8f7b\u91cf\u7ea7\u7684\u6570\u636e\u4ea4\u6362\u683c\u5f0f&#xff0c;\u6b63\u597d\u80fd\u6ee1\u8db3\u6211\u4eec\u7684\u9700\u6c42\u3002\u800c Python \u4e2d\u7684 json \u5e93&#xff0c;\u5219\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u7b80\u5355\u6613\u7528\u7684\u63a5\u53e3\u6765\u5904\u7406 JSON \u6570\u636e\u3002<\/p>\n<h2 id=\"2.%20json%20%E5%BA%93%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5\">2. json \u5e93\u57fa\u672c\u6982\u5ff5<\/h2>\n<p>JSON \u662f\u4e00\u79cd\u57fa\u4e8e\u6587\u672c\u683c\u5f0f\u7684\u6570\u636e\u8868\u793a\u65b9\u6cd5&#xff0c;\u6613\u4e8e\u548c\u9605\u8bfb\u7f16\u5199&#xff0c;\u540c\u65f6\u4e5f\u6613\u4e8e\u673a\u5668\u89e3\u6790\u548c\u751f\u6210\u3002\u5b83\u57fa\u4e8e JavaScript \u7684\u4e00\u4e2a\u5b50\u96c6&#xff0c;\u4f46\u5df2\u7ecf\u6210\u4e3a\u4e00\u79cd\u72ec\u7acb\u7684\u6570\u636e\u683c\u5f0f&#xff0c;\u88ab\u5e7f\u6cdb\u5e94\u7528\u4e8e\u5404\u79cd\u7f16\u7a0b\u8bed\u8a00\u4e2d\u3002\u5728 Python \u4e2d&#xff0c;json \u5e93\u5c31\u662f\u4e13\u95e8\u7528\u4e8e\u5904\u7406 JSON \u6570\u636e\u7684\u3002<\/p>\n<p>JSON \u6570\u636e\u7ed3\u6784\u4e3b\u8981\u5305\u62ec\u4ee5\u4e0b\u4e24\u79cd\u57fa\u672c\u7c7b\u578b&#xff1a;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5bf9\u8c61 &#xff08;Object&#xff09; &#xff1a;\u4e00\u7ec4\u65e0\u5e8f\u7684\u952e\u503c\u5bf9&#xff0c;\u7c7b\u4f3c\u4e8e Python \u4e2d\u7684\u5b57\u5178\u3002\u4f8b\u5982&#xff1a;{&#034;name&#034;: &#034;John&#034;, &#034;age&#034;: 30}&#xff0c;\u5176\u4e2d &#034;name&#034; \u548c &#034;age&#034; \u662f\u952e&#xff0c;\u5bf9\u5e94\u7684\u503c\u5206\u522b\u662f &#034;John&#034; \u548c 30 \u3002<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u6570\u7ec4&#xff08;Array&#xff09; &#xff1a;\u4e00\u4e2a\u6709\u5e8f\u7684\u503c\u7684\u96c6\u5408&#xff0c;\u7c7b\u4f3c\u4e8e Python \u4e2d\u7684\u5217\u8868\u3002\u4f8b\u5982&#xff1a;[1, 2, 3, 4]\u3002<\/p>\n<p>json \u5e93\u7684\u6838\u5fc3\u529f\u80fd\u5c31\u662f\u5b9e\u73b0 Python \u6570\u636e\u7c7b\u578b\u4e0e JSON \u6570\u636e\u7c7b\u578b\u7684\u76f8\u4e92\u8f6c\u6362\u3002<\/p>\n<h2 id=\"3.%20json%20%E7%9A%84%E9%80%82%E5%BA%94%E5%9C%BA%E6%99%AF\">3. json \u7684\u9002\u5e94\u573a\u666f<\/h2>\n<ul>\n<li>\n<p>\u6570\u636e\u5b58\u50a8 &#xff1a;\u5c06\u6570\u636e\u4ee5 JSON \u683c\u5f0f\u5b58\u50a8\u5230\u6587\u4ef6\u6216\u6570\u636e\u5e93\u4e2d&#xff0c;\u4fbf\u4e8e\u540e\u7eed\u8bfb\u53d6\u548c\u4fee\u6539\u3002\u4f8b\u5982&#xff0c;\u4fdd\u5b58\u914d\u7f6e\u6587\u4ef6\u3001\u7528\u6237\u6570\u636e\u7b49\u3002<\/p>\n<\/li>\n<li>\n<p>\u6570\u636e\u4ea4\u6362 &#xff1a;\u5728\u4e0d\u540c\u7684\u7cfb\u7edf\u6216\u7ec4\u4ef6\u4e4b\u95f4\u4f20\u9012\u6570\u636e&#xff0c;\u7279\u522b\u662f\u5728 \u5f00 Web\u53d1\u4e2d&#xff0c;\u524d\u540e\u7aef\u4e4b\u95f4\u5e38\u7528 JSON \u683c\u5f0f\u8fdb\u884c\u6570\u636e\u4ea4\u4e92\u3002<\/p>\n<\/li>\n<li>\n<p>API \u6570\u636e\u5904\u7406 &#xff1a;\u8bb8\u591a Web API \u8fd4\u56de\u7684\u6570\u636e\u90fd\u662f JSON \u683c\u5f0f&#xff0c;\u4f7f\u7528 json \u5e93\u53ef\u4ee5\u65b9\u4fbf\u5730\u89e3\u6790\u548c\u5904\u7406\u8fd9\u4e9b\u6570\u636e\u3002<\/p>\n<\/li>\n<\/ul>\n<h2 id=\"4.%20json%20%E5%BA%93%E7%9A%84%E5%9F%BA%E6%9C%AC%E7%94%A8%E6%B3%95\">4. json \u5e93\u7684\u57fa\u672c\u7528\u6cd5<\/h2>\n<h3 id=\"4.1%20%E5%AF%BC%20json%E5%85%A5%20%E6%A8%A1%E5%9D%97\">4.1 \u5bfc json\u5165 \u6a21\u5757<\/h3>\n<p>\u5728 Python \u4e2d&#xff0c;\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u5185\u7f6e\u7684 json \u6a21\u5757&#xff0c;\u65e0\u9700\u989d\u5916\u5b89\u88c5\u3002\u901a\u8fc7\u4ee5\u4e0b\u4ee3\u7801\u5bfc\u5165 json \u6a21\u5757&#xff1a;<\/p>\n<p>import json <\/p>\n<h3 id=\"4.2%20%E5%B0%86%20Python%20%E5%AF%B9%E8%B1%A1%E8%BD%AC%E6%8D%A2%E4%B8%BA%20JSON%20%E5%AD%97%E7%AC%A6%E4%B8%B2\">4.2 \u5c06 Python \u5bf9\u8c61\u8f6c\u6362\u4e3a JSON \u5b57\u7b26\u4e32<\/h3>\n<p>\u4f7f\u7528 json.dumps() \u65b9\u6cd5\u5c06\u53ef\u4ee5 Python \u5bf9\u8c61&#xff08;\u5982\u5b57\u5178\u3001\u5217\u8868\u7b49&#xff09;\u8f6c\u6362\u4e3a JSON \u683c\u5f0f\u7684\u5b57\u7b26\u4e32\u3002\u8fd9\u4e2a\u65b9\u6cd5\u7684\u8bed\u6cd5\u5982\u4e0b&#xff1a;<\/p>\n<p>json.dumps(obj, *, skipkeys&#061;False, ensure_ascii&#061;True, check_circular&#061;True, allow_nan&#061;True, cls&#061;None, indent&#061;None, separators&#061;None default,&#061;None, sort_keys&#061;False, **kw) <\/p>\n<p>\u5176\u4e2d&#xff0c;obj \u662f\u8981\u8f6c\u6362\u7684 Python \u5bf9\u8c61&#xff0c;\u5176\u4ed6\u53c2\u6570\u7528\u4e8e\u63a7\u5236\u8f6c\u6362\u8fc7\u7a0b\u4e2d\u7684\u5404\u79cd\u9009\u9879\u3002<\/p>\n<p>\u793a\u4f8b &#xff1a;<\/p>\n<p>data &#061; {<br \/>\n    &#034;name&#034;: &#034;John&#034;,<br \/>\n    &#034;age&#034;: 03,<br \/>\n    &#034;city&#034;: &#034;New York&#034;<br \/>\n}<\/p>\n<p>json_str &#061; json.dumps(data)<br \/>\nprint(json_str) <\/p>\n<p>\u8f93\u51fa\u7ed3\u679c&#xff1a;<\/p>\n<p>{&#034;name&#034;: &#034;John&#034;, &#034;age&#034;: 30, &#034;city&#034;: &#034;New York&#034;} <\/p>\n<p>\u53ef\u4ee5\u770b\u5230&#xff0c;Python \u5b57\u5178\u88ab\u6210\u529f\u8f6c\u6362\u4e3a JSON \u683c\u5f0f\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<h3 id=\"4.3%20%E5%B0%86%20JSON%20%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%BD%AC%E6%8D%A2%E4%B8%BA%20Python%20%E5%AF%B9%E8%B1%A1\">4.3 \u5c06 JSON \u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a Python \u5bf9\u8c61<\/h3>\n<p>\u4f7f\u7528 json.loads() \u65b9\u6cd5\u53ef\u4ee5\u5c06 JSON \u683c\u5b57\u7b26\u4e32\u5f0f\u7684\u8f6c\u6362\u4e3a Python \u5bf9\u8c61\u3002\u8fd9\u4e2a\u65b9\u6cd5\u7684\u8bed\u6cd5\u5982\u4e0b&#xff1a;<\/p>\n<p>json.loads(s, *, cls&#061;None, object_hook&#061;None, parse_float&#061;None, parse_int&#061;None, parse_constant&#061;None, object_pairs_hook&#061;None, **kw) <\/p>\n<p>\u5176\u4e2d&#xff0c;s \u662f JSON \u683c\u5f0f\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<p>\u793a\u4f8b &#xff1a;<\/p>\n<p>json_str &#061; &#039;{&#034;name&#034;: &#034;John&#034;, &#034;age&#034;: 30, &#034;city&#034;: &#034;New York&#034;}&#039;<\/p>\n<p>data &#061; json.loads(json_str)<br \/>\nprint(data)<br \/>\nprint(type(data)) <\/p>\n<p>\u8f93\u51fa\u7ed3\u679c&#xff1a;<\/p>\n<p>{&#039;name&#039;: &#039;John&#039;, &#039;age&#039;: 30, &#039;city&#039;: &#039;New York&#039;}<br \/>\n&lt;class &#039;dict&#039;&gt; <\/p>\n<p>JSON \u5b57\u7b26\u4e32\u88ab\u8f6c\u6362\u4e3a \u5b57 Python\u5178\u3002<\/p>\n<h3 id=\"4.4%20%E5%B0%86%20Python%20%E5%AF%B9%E8%B1%A1%E5%86%99%E5%85%A5%20JSON%20%E6%96%87%E4%BB%B6\">4.4 \u5c06 Python \u5bf9\u8c61\u5199\u5165 JSON \u6587\u4ef6<\/h3>\n<p>\u4f7f\u7528 json.dump() \u65b9\u6cd5\u53ef\u4ee5\u76f4\u63a5\u5c06 Python \u5bf9\u8c61\u5199\u5165\u5230 JSON \u6587\u4ef6\u4e2d\u3002\u8fd9\u4e2a\u65b9\u6cd5\u7684\u8bed\u6cd5\u5982\u4e0b&#xff1a;<\/p>\n<p>json.dump(obj, fp, *, skipkeys&#061;False, ensure_ascii&#061;True, check_circular&#061;True, allow_nan&#061;True, cls&#061;None, indent&#061;None, separators&#061;None, default&#061;None, sort_keys&#061;False, **kw) <\/p>\n<p>\u5176\u4e2d&#xff0c;obj \u662f\u8981\u5199\u5165\u7684 Python \u5bf9\u8c61&#xff0c;fp \u662f\u4e00\u4e2a\u6587\u4ef6\u5bf9\u8c61\u3002<\/p>\n<p>\u793a\u4f8b &#xff1a;<\/p>\n<p>data &#061; {<br \/>\n    &#034;name&#034;: &#034;John&#034;,<br \/>\n    &#034;age&#034;: 30,<br \/>\n    &#034;city&#034;: &#034;New York&#034;<br \/>\n}<\/p>\n<p>with open(&#034;data.json&#034;, &#034;w&#034;) as f:<br \/>\n    json.dump(data, f) <\/p>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u5c06 Python \u5b57\u5178\u5199\u5165\u5230\u540d\u4e3a \u201cdata.json\u201d \u7684\u6587\u4ef6\u4e2d\u3002<\/p>\n<h3 id=\"4.5%20%E4%BB%8E%20JSON%20%E6%96%87%E4%BB%B6%E8%AF%BB%E5%8F%96%E6%95%B0%E6%8D%AE\">4.5 \u4ece JSON \u6587\u4ef6\u8bfb\u53d6\u6570\u636e<\/h3>\n<p>\u4f7f\u7528 json.load() \u65b9\u6cd5\u53ef\u4ee5\u4ece JSON \u6587\u4ef6\u4e2d\u8bfb\u53d6\u6570\u636e\u5e76\u8f6c\u6362\u4e3a Python \u5bf9\u8c61\u3002\u8fd9\u4e2a\u65b9\u6cd5\u7684\u8bed\u6cd5\u5982\u4e0b&#xff1a;<\/p>\n<p>json.load(fp, *, cls&#061;None, object_hook&#061;None, parse_float&#061;None, parse_int&#061;None, parse_constant&#061;None, object_pairs_hook&#061;None, **kw) <\/p>\n<p>\u5176\u4e2d&#xff0c;fp \u662f\u4e00\u4e2a\u6587\u4ef6\u5bf9\u8c61\u3002<\/p>\n<p>\u793a\u4f8b &#xff1a;<\/p>\n<p>with open(&#034;data.json&#034;, &#034;r&#034;) as f:<br \/>\n    data &#061; json.load(f)<br \/>\n    print(data) <\/p>\n<p>\u8bfb\u53d6 \u201cdata.json\u201d \u6587\u4ef6\u4e2d\u7684\u6570\u636e\u5e76\u6253\u5370\u51fa\u6765\u3002<\/p>\n<h3 id=\"4.6%20json%20%E7%9A%84%E5%85%B6%E4%BB%96%E6%96%B9%E6%B3%95\">4.6 json \u7684\u5176\u4ed6\u65b9\u6cd5<\/h3>\n<p>\u9664\u4e86\u4e0a\u8ff0\u5e38\u7528\u7684 dumps()\u3001loads()\u3001dump() \u548c load() \u65b9\u6cd5\u5916&#xff0c;json \u5e93\u8fd8\u63d0\u4f9b\u4e86\u4e00\u4e9b\u5176\u4ed6\u65b9\u6cd5\u548c\u5e38\u91cf&#xff0c;\u7528\u4e8e\u5904\u7406\u7279\u6b8a\u60c5\u51b5\u3002<\/p>\n<ul>\n<li>\n<p>json.JSONEncoder \u548c json.JSONDecoder&#xff1a;\u8fd9\u4e24\u4e2a\u7c7b\u5206\u522b\u7528\u4e8e\u81ea\u5b9a\u4e49 JSON \u7f16\u7801\u5668\u548c\u89e3\u7801\u5668&#xff0c;\u53ef\u4ee5\u5904\u7406\u4e00\u4e9b\u7279\u6b8a\u7684\u7c7b\u578b\u8f6c\u6362\u95ee\u9898\u3002<\/p>\n<\/li>\n<li>\n<p>json.JSONDecodeError&#xff1a;\u5f53\u89e3\u6790 JSON \u6570\u636e\u51fa\u9519\u65f6&#xff0c;\u4f1a\u629b\u51fa\u8fd9\u4e2a\u5f02\u5e38&#xff0c;\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u8fdb\u884c\u9519\u8bef\u5904\u7406\u3002<\/p>\n<\/li>\n<\/ul>\n<h2 id=\"5.%20json%20%E5%BA%93%E7%9A%84%E9%AB%98%E7%BA%A7%E7%94%A8%E6%B3%95\">5. json \u5e93\u7684\u9ad8\u7ea7\u7528\u6cd5<\/h2>\n<h3 id=\"5.1%20%E8%87%AA%E5%AE%9A%E4%B9%89%E5%AF%B9%E8%B1%A1%E7%9A%84%E5%BA%8F%E5%88%97%E5%8C%96%E4%B8%8E%E5%8F%8D%E5%BA%8F%E5%88%97%E5%8C%96%E5%9C%A8\">5.1 \u81ea\u5b9a\u4e49\u5bf9\u8c61\u7684\u5e8f\u5217\u5316\u4e0e\u53cd\u5e8f\u5217\u5316\u5728<\/h3>\n<p>\u5b9e\u9645\u5f00\u53d1\u4e2d&#xff0c;\u6211\u4eec\u53ef\u80fd\u4f1a\u9047\u5230\u9700\u8981\u5e8f\u5217\u5316\u81ea\u5b9a\u4e49\u5bf9\u8c61\u7684\u60c5\u51b5\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b&#xff0c;json \u5e93\u65e0\u6cd5\u76f4\u63a5\u5e8f\u5217\u5316\u81ea\u5b9a\u4e49\u5bf9\u8c61&#xff0c;\u4f46\u6211\u4eec\u53ef\u4ee5\u81ea\u5b9a\u4e49\u4e00\u4e2a\u7f16\u7801\u5668\u6765\u5b9e\u73b0\u8fd9\u4e2a\u529f\u80fd\u3002<\/p>\n<p>import json<\/p>\n<p>class Person:<br \/>\n    def __init__(self, name, age):<br \/>\n        self.name &#061; name<br \/>\n        self.age &#061; age<\/p>\n<p>class PersonEncoder(json.JSONEncoder):<br \/>\n    def default(self, obj):<br \/>\n        if isinstance(obj, Person):<br \/>\n            return {&#034;name&#034;: obj.name, &#034;age&#034;: obj.age}<br \/>\n        return super().default(obj)<\/p>\n<p>person &#061; Person(&#034;John&#034;, 30)<br \/>\njson_str &#061; json.dumps(person, cls&#061;PersonEncoder)<br \/>\nprint(json_str) <\/p>\n<p>\u8f93\u51fa\u7ed3\u679c&#xff1a;<\/p>\n<p>{&#034;name&#034;: &#034;John&#034;, &#034;age&#034;: 30} <\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u901a\u8fc7&#xff0c;\u81ea\u5b9a\u4e49\u7f16\u7801\u5668&#xff0c;\u6210\u529f\u5c06\u81ea\u5b9a\u4e49\u7684 Person \u5bf9\u8c61\u5e8f\u5217\u5316\u4e3a JSON \u5b57\u7b26\u4e32\u3002\u540c\u6837\u5730&#xff0c;\u6211\u4eec\u4e5f\u53ef\u4ee5\u901a\u8fc7\u81ea\u5b9a\u4e49\u89e3\u7801\u5668\u6765\u5b9e\u73b0 JSON \u5b57\u7b26\u4e32\u5230\u81ea\u5b9a\u4e49\u5bf9\u8c61\u7684\u53cd\u5e8f\u5217\u5316\u3002<\/p>\n<h3 id=\"5.2%20%E5%A4%84%E7%90%86%E9%9D%9E%20ASCII%20%E5%AD%97%E7%AC%A6\">5.2 \u5904\u7406\u975e ASCII \u5b57\u7b26<\/h3>\n<p>\u5728\u5904\u7406\u5305\u542b\u975e ASCII \u5b57\u7b26\u7684 JSON \u6570\u636e\u65f6&#xff0c;\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 ensure_ascii \u53c2\u6570\u6765\u63a7\u5236\u662f\u5426\u5c06\u975e ASCII \u5b57\u7b26\u8f6c\u4e49\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b&#xff0c;ensure_ascii \u53c2\u6570\u4e3a True&#xff0c;\u975e ASCII \u5b57\u7b26\u4f1a\u88ab\u8f6c\u4e49\u4e3a Unicode \u7f16\u7801\u3002<\/p>\n<p>data &#061; {&#034;name&#034;: &#034;\u5f20\u4e09&#034;, &#034;city&#034;: &#034;\u5317\u4eac&#034;}<br \/>\njson_str &#061; json.dumps(data, ensure_ascii&#061;False)<br \/>\nprint(json_str) <\/p>\n<p>\u8f93\u51fa\u7ed3\u679c&#xff1a;<\/p>\n<p>{&#034;name&#034;: &#034;\u5f20\u4e09&#034;, &#034;city&#034;: &#034;\u5317\u4eac&#034;} <\/p>\n<p>\u5f53 ensure_ascii \u53c2\u6570\u4e3a False \u65f6&#xff0c;\u975e ASCII \u5b57\u7b26\u4f1a\u4ee5\u539f\u59cb\u5f62\u5f0f\u8f93\u51fa&#xff0c;\u8fd9\u6837\u66f4\u4fbf\u4e8e\u9605\u8bfb\u548c\u7406\u89e3\u3002<\/p>\n<h3 id=\"5.3%20%E4%BD%BF%E7%94%A8%20indent%20%E5%8F%82%E6%95%B0%E7%BE%8E%E5%8C%96%E8%BE%93%E5%87%BA\">5.3 \u4f7f\u7528 indent \u53c2\u6570\u7f8e\u5316\u8f93\u51fa<\/h3>\n<p>\u5728\u8c03\u8bd5\u6216\u9605\u8bfb JSON \u6570\u636e\u65f6&#xff0c;\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e indent \u53c2\u6570\u6765\u7f8e\u5316 JSON \u8f93\u51fa\u7684\u683c\u5f0f&#xff0c;\u4f7f\u5176\u66f4\u6613\u4e8e\u548c\u9605\u8bfb\u3002indent \u53c2\u6570\u6307\u5b9a\u4e86\u7f29\u8fdb\u7684\u7a7a\u683c\u6570\u3002<\/p>\n<p>data &#061; {<br \/>\n    &#034;name&#034;: &#034;John&#034;,<br \/>\n    &#034;age&#034;: 30,<br \/>\n    &#034;hobbies&#034;: [&#034;reading&#034;, &#034;traveling&#034;, &#034;sports&#034;]<br \/>\n}<\/p>\n<p>json_str &#061; json.dumps(data, indent&#061;4)<br \/>\nprint(json_str) <\/p>\n<p>\u8f93\u51fa\u7ed3\u679c&#xff1a;<\/p>\n<p>{<br \/>\n    &#034;name&#034;: &#034;John&#034;,<br \/>\n    &#034;age&#034;: 30,<br \/>\n    &#034;hobbies&#034;: [<br \/>\n        &#034;reading&#034;,<br \/>\n        &#034;traveling&#034;,<br \/>\n        &#034;sports&#034;<br \/>\n    ]<br \/>\n} <\/p>\n<p>\u53ef\u4ee5\u770b\u5230&#xff0c;\u901a\u8fc7\u8bbe\u7f6e indent \u53c2\u6570&#xff0c;\u8f93\u51fa\u7684 JSON \u6570\u636e\u683c\u5f0f\u66f4\u52a0\u6e05\u6670\u7f8e\u89c2\u3002<\/p>\n<h2 id=\"6.%20json%20%E5%BA%93%E7%9A%84%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86\">6. json \u5e93\u7684\u5f02\u5e38\u5904\u7406<\/h2>\n<p>\u5728\u4f7f\u7528 json \u5e93\u8fdb\u884c\u6570\u636e\u5904\u7406\u65f6&#xff0c;\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u5f02\u5e38\u60c5\u51b5\u4f8b\u5982&#xff0c;\u65e0\u6548\u7684 JSON \u683c\u5f0f\u3001\u4e0d\u652f\u6301\u7684\u6570\u636e\u7c7b\u578b\u7b49\u3002\u6211\u4eec\u9700\u8981\u5bf9\u8fd9\u4e9b\u5f02\u5e38\u8fdb\u884c\u6709\u6548\u7684\u5904\u7406&#xff0c;\u4ee5\u786e\u4fdd\u7a0b\u5e8f\u7684\u5065\u58ee\u6027\u3002<\/p>\n<h3 id=\"6.1%20%E5%B8%B8%E8%A7%81%E7%9A%84%E5%BC%82%E5%B8%B8%E7%B1%BB%E5%9E%8B\">6.1 \u5e38\u89c1\u7684\u5f02\u5e38\u7c7b\u578b<\/h3>\n<ul>\n<li>\n<p>json.JSONDecodeError&#xff1a;\u5f53\u89e3\u6790 JSON \u6570\u636e\u51fa\u9519\u65f6\u629b\u51fa&#xff0c;\u4f8b\u5982 JSON \u683c\u5f0f\u4e0d\u6b63\u786e\u3002<\/p>\n<\/li>\n<li>\n<p>TypeError&#xff1a;\u5f53\u5c1d\u8bd5\u5e8f\u5217\u5316\u4e00\u4e2a\u4e0d\u652f\u6301\u7684\u6570\u636e\u7c7b\u578b\u65f6\u629b\u51fa\u3002<\/p>\n<\/li>\n<\/ul>\n<h3 id=\"6.2%20%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86%E7%A4%BA%E4%BE%8B\">6.2 \u5f02\u5e38\u5904\u7406\u793a\u4f8b<\/h3>\n<p>import json<\/p>\n<p>json_str &#061; &#039;{&#034;name&#034;: &#034;John&#034;, &#034;age&#034;: 30, &#034;hobbies&#034;: [&#034;reading&#034;, &#034;traveling&#034;]&#039;<br \/>\ntry:<br \/>\n    data &#061; json.loads(json_str)<br \/>\nexcept json.JSONDecodeError as e:<br \/>\n    print(f&#034;JSON \u89e3\u7801\u9519\u8bef&#xff1a;{e}&#034;)<br \/>\nexcept Exception as e:<br \/>\n    print(f&#034;\u53d1\u751f\u9519\u8bef&#xff1a;{e}&#034;) <\/p>\n<p>\u8f93\u51fa\u7ed3\u679c&#xff1a;<\/p>\n<p>JSON \u89e3\u7801\u9519\u8bef&#xff1a;Expecting &#039;,&#039; delimiter: line 1 column 46 (char 45) <\/p>\n<p>\u901a\u8fc7\u6355\u83b7\u5f02\u5e38&#xff0c;\u6211\u4eec\u53ef\u4ee5\u53ca\u65f6\u53d1\u73b0\u5e76\u5904\u7406\u95ee\u9898&#xff0c;\u907f\u514d\u7a0b\u5e8f\u5d29\u6e83\u3002<\/p>\n<h2 id=\"7.%20%E6%80%BB%E7%BB%93\">7. \u603b\u7ed3<\/h2>\n<p>json \u5e93\u4f5c\u4e3a Python \u7684\u5185\u7f6e\u6a21\u5757&#xff0c;\u662f\u6211\u4eec\u5728\u8fdb\u884c\u6570\u636e\u5b58\u50a8\u3001\u4f20\u9012\u548c\u4ea4\u6362\u65f6\u4e0d\u53ef\u6216\u7f3a\u7684\u5de5\u5177\u4e4b\u4e00\u3002\u5176\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u7b80\u5355\u800c\u5f3a\u5927\u7684\u5de5\u5177\u6765\u5904\u7406 JSON \u6570\u636e\u3002\u5b83\u4e0d\u4ec5\u80fd\u591f\u8f7b\u677e\u5730\u5b9e\u73b0 Python \u5bf9\u8c61\u4e0e JSON \u6570\u636e\u4e4b\u95f4\u7684\u76f8\u4e92\u8f6c\u6362&#xff0c;\u8fd8\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u53c2\u6570\u548c\u65b9\u6cd5\u6765\u6ee1\u8db3\u5404\u79cd\u590d\u6742\u7684\u9700\u6c42\u3002\u6211\u662f\u6a59\u8272\u5c0f\u535a&#xff0c;\u5173\u6ce8\u6211&#xff0c;\u4e00\u8d77\u5728\u4eba\u5de5\u667a\u80fd\u9886\u57df\u5b66\u4e60\u8fdb\u6b65&#xff01;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb979\u6b21\uff0c\u70b9\u8d5e12\u6b21\uff0c\u6536\u85cf14\u6b21\u3002\u5728\u6211\u4eec\u65e5\u5e38\u7684 Python \u7f16\u7a0b\u4e2d\uff0c\u6570\u636e\u7684\u5b58\u50a8\u4e0e\u4f20\u9012\u662f\u4e0d\u53ef\u907f\u514d\u7684\u4e00\u4e2a\u73af\u8282\u3002\u60f3\u8c61\u4e00\u4e0b\uff0c\u6211\u4eec\u5728\u5f00\u53d1\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u9700\u8981\u5c06\u4e00\u4e9b\u914d\u7f6e\u4fe1\u606f\u5b58\u50a8\u8d77\u6765\uff0c\u6216\u8005\u8981\u5c06\u6570\u636e\u53d1\u9001\u5230\u53e6\u4e00\u4e2a\u7cfb\u7edf\u4e2d\u3002\u8fd9\u65f6\u5019\uff0c\u6211\u4eec\u5c31\u9700\u8981\u4e00\u79cd\u9ad8\u6548\u3001\u4fbf\u6377\u7684\u65b9\u5f0f\u6765\u5b8c\u6210\u8fd9\u4e2a\u3002\u4efb\u52a1JSON\uff08JavaScript Object Notation\uff09\uff0c\u4f5c\u4e3a\u4e00\u79cd\u8f7b\u91cf\u7ea7\u7684\u6570\u636e\u4ea4\u6362\u683c\u5f0f\uff0c\u6b63\u597d\u80fd\u6ee1\u8db3\u6211\u4eec\u7684\u9700\u6c42\u3002\u800c Python \u4e2d\u7684 json \u5e93\uff0c\u5219\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u7b80\u5355\u6613\u7528\u7684\u63a5\u53e3\u6765\u5904\u7406 JSON \u6570\u636e\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[93,81,3054,100,3055],"topic":[],"class_list":{"0":"post-35755","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-server","7":"tag-json","8":"tag-python","10":"tag-100","11":"tag-3055"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python\u4e2d\u7684JSON\u5e93\uff0c\u8be6\u7ec6\u4ecb\u7ecd\u4e0e\u4ee3\u7801\u793a\u4f8b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/35755.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python\u4e2d\u7684JSON\u5e93\uff0c\u8be6\u7ec6\u4ecb\u7ecd\u4e0e\u4ee3\u7801\u793a\u4f8b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb979\u6b21\uff0c\u70b9\u8d5e12\u6b21\uff0c\u6536\u85cf14\u6b21\u3002\u5728\u6211\u4eec\u65e5\u5e38\u7684 Python \u7f16\u7a0b\u4e2d\uff0c\u6570\u636e\u7684\u5b58\u50a8\u4e0e\u4f20\u9012\u662f\u4e0d\u53ef\u907f\u514d\u7684\u4e00\u4e2a\u73af\u8282\u3002\u60f3\u8c61\u4e00\u4e0b\uff0c\u6211\u4eec\u5728\u5f00\u53d1\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u9700\u8981\u5c06\u4e00\u4e9b\u914d\u7f6e\u4fe1\u606f\u5b58\u50a8\u8d77\u6765\uff0c\u6216\u8005\u8981\u5c06\u6570\u636e\u53d1\u9001\u5230\u53e6\u4e00\u4e2a\u7cfb\u7edf\u4e2d\u3002\u8fd9\u65f6\u5019\uff0c\u6211\u4eec\u5c31\u9700\u8981\u4e00\u79cd\u9ad8\u6548\u3001\u4fbf\u6377\u7684\u65b9\u5f0f\u6765\u5b8c\u6210\u8fd9\u4e2a\u3002\u4efb\u52a1JSON\uff08JavaScript Object Notation\uff09\uff0c\u4f5c\u4e3a\u4e00\u79cd\u8f7b\u91cf\u7ea7\u7684\u6570\u636e\u4ea4\u6362\u683c\u5f0f\uff0c\u6b63\u597d\u80fd\u6ee1\u8db3\u6211\u4eec\u7684\u9700\u6c42\u3002\u800c Python \u4e2d\u7684 json \u5e93\uff0c\u5219\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u7b80\u5355\u6613\u7528\u7684\u63a5\u53e3\u6765\u5904\u7406 JSON \u6570\u636e\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/35755.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-06T09:15:54+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/35755.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/35755.html\",\"name\":\"Python\u4e2d\u7684JSON\u5e93\uff0c\u8be6\u7ec6\u4ecb\u7ecd\u4e0e\u4ee3\u7801\u793a\u4f8b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-06T09:15:54+00:00\",\"dateModified\":\"2025-05-06T09:15:54+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/35755.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/35755.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/35755.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\u4e2d\u7684JSON\u5e93\uff0c\u8be6\u7ec6\u4ecb\u7ecd\u4e0e\u4ee3\u7801\u793a\u4f8b\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python\u4e2d\u7684JSON\u5e93\uff0c\u8be6\u7ec6\u4ecb\u7ecd\u4e0e\u4ee3\u7801\u793a\u4f8b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/35755.html","og_locale":"zh_CN","og_type":"article","og_title":"Python\u4e2d\u7684JSON\u5e93\uff0c\u8be6\u7ec6\u4ecb\u7ecd\u4e0e\u4ee3\u7801\u793a\u4f8b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb979\u6b21\uff0c\u70b9\u8d5e12\u6b21\uff0c\u6536\u85cf14\u6b21\u3002\u5728\u6211\u4eec\u65e5\u5e38\u7684 Python \u7f16\u7a0b\u4e2d\uff0c\u6570\u636e\u7684\u5b58\u50a8\u4e0e\u4f20\u9012\u662f\u4e0d\u53ef\u907f\u514d\u7684\u4e00\u4e2a\u73af\u8282\u3002\u60f3\u8c61\u4e00\u4e0b\uff0c\u6211\u4eec\u5728\u5f00\u53d1\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u9700\u8981\u5c06\u4e00\u4e9b\u914d\u7f6e\u4fe1\u606f\u5b58\u50a8\u8d77\u6765\uff0c\u6216\u8005\u8981\u5c06\u6570\u636e\u53d1\u9001\u5230\u53e6\u4e00\u4e2a\u7cfb\u7edf\u4e2d\u3002\u8fd9\u65f6\u5019\uff0c\u6211\u4eec\u5c31\u9700\u8981\u4e00\u79cd\u9ad8\u6548\u3001\u4fbf\u6377\u7684\u65b9\u5f0f\u6765\u5b8c\u6210\u8fd9\u4e2a\u3002\u4efb\u52a1JSON\uff08JavaScript Object Notation\uff09\uff0c\u4f5c\u4e3a\u4e00\u79cd\u8f7b\u91cf\u7ea7\u7684\u6570\u636e\u4ea4\u6362\u683c\u5f0f\uff0c\u6b63\u597d\u80fd\u6ee1\u8db3\u6211\u4eec\u7684\u9700\u6c42\u3002\u800c Python \u4e2d\u7684 json \u5e93\uff0c\u5219\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u7b80\u5355\u6613\u7528\u7684\u63a5\u53e3\u6765\u5904\u7406 JSON \u6570\u636e\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/35755.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-06T09:15:54+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/35755.html","url":"https:\/\/www.wsisp.com\/helps\/35755.html","name":"Python\u4e2d\u7684JSON\u5e93\uff0c\u8be6\u7ec6\u4ecb\u7ecd\u4e0e\u4ee3\u7801\u793a\u4f8b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-06T09:15:54+00:00","dateModified":"2025-05-06T09:15:54+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/35755.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/35755.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/35755.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Python\u4e2d\u7684JSON\u5e93\uff0c\u8be6\u7ec6\u4ecb\u7ecd\u4e0e\u4ee3\u7801\u793a\u4f8b"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/35755","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=35755"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/35755\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=35755"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=35755"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=35755"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=35755"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}