{"id":176910,"date":"2024-05-08T19:20:24","date_gmt":"2024-05-08T11:20:24","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/176910.html"},"modified":"2024-05-08T19:20:31","modified_gmt":"2024-05-08T11:20:31","slug":"python%e8%a7%a3%e6%9e%90%e8%be%83%e5%a4%a7%e7%9a%84json%e6%96%87%e4%bb%b6%e6%8a%a5%e5%bc%82%e5%b8%b8%ef%bc%8c%e6%80%8e%e4%b9%88%e5%a4%84%e7%90%86","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/176910.html","title":{"rendered":"python\u89e3\u6790\u8f83\u5927\u7684json\u6587\u4ef6\u62a5\u5f02\u5e38\uff0c\u600e\u4e48\u5904\u7406"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/27060741\/0ae9af3f-0a5d-4eee-babb-bb26d0f62e96.webp\" alt=\"python\u89e3\u6790\u8f83\u5927\u7684json\u6587\u4ef6\u62a5\u5f02\u5e38\uff0c\u600e\u4e48\u5904\u7406\" \/><\/p>\n<p><p><strong>\u5728\u5904\u7406\u8f83\u5927\u7684JSON\u6587\u4ef6\u65f6\uff0c\u5e38\u89c1\u7684\u5f02\u5e38\u5305\u62ec\u5185\u5b58\u6ea2\u51fa\u3001\u89e3\u6790\u65f6\u95f4\u8fc7\u957f\u3001\u89e3\u6790\u9519\u8bef\u7b49\u3002\u89e3\u51b3\u8fd9\u4e9b\u5f02\u5e38\u7684\u65b9\u6cd5\u4e3b\u8981\u6709\uff1a\u4f7f\u7528\u6d41\u5f0f\u89e3\u6790\u3001\u9012\u589e\u5f0f\u89e3\u6790\u3001\u4f7f\u7528\u5185\u5b58\u6620\u5c04\u6587\u4ef6<\/strong>\u3002\u6d41\u5f0f\u89e3\u6790\u548c\u9012\u589e\u5f0f\u89e3\u6790\u53ef\u4ee5\u964d\u4f4e\u5185\u5b58\u4f7f\u7528\u3001\u63d0\u9ad8\u89e3\u6790\u6548\u7387\uff0c\u800c\u4f7f\u7528\u5185\u5b58\u6620\u5c04\u6587\u4ef6\u5219\u53ef\u4ee5\u5904\u7406\u8d85\u5927\u6587\u4ef6\u4e14\u964d\u4f4e\u5bf9\u5185\u5b58\u7684\u4f9d\u8d56\u3002<\/p>\n<\/p>\n<p><p>\u5c55\u5f00\u63cf\u8ff0<strong>\u6d41\u5f0f\u89e3\u6790<\/strong>\uff1a<\/p>\n<p>\u6d41\u5f0f\u89e3\u6790\u662f\u4e00\u79cd\u8fb9\u8bfb\u53d6\u8fb9\u89e3\u6790\u7684\u65b9\u6cd5\uff0c\u8fd9\u79cd\u65b9\u6cd5\u4e0d\u9700\u8981\u4e00\u6b21\u6027\u628a\u6574\u4e2a\u6587\u4ef6\u8bfb\u5165\u5185\u5b58\uff0c\u800c\u662f\u9010\u6b65\u8bfb\u53d6\u6587\u4ef6\u7684\u5185\u5bb9\uff0c\u5e76\u8fb9\u8bfb\u8fb9\u89e3\u6790\uff0c\u9002\u7528\u4e8e\u5904\u7406\u5927\u578bJSON\u6587\u4ef6\u3002Python\u7684<code>ijson<\/code>\u5e93\u5c31\u662f\u4e00\u4e2a\u652f\u6301\u6d41\u5f0f\u89e3\u6790JSON\u6587\u4ef6\u7684\u5e93\u3002\u5b83\u53ef\u4ee5\u4ece\u6587\u4ef6\u3001\u7f51\u7edc\u4f20\u8f93\u7b49\u6e90\u4e2d\u9010\u6b65\u8bfb\u53d6\u5e76\u751f\u6210JSON\u5bf9\u8c61\uff0c\u4ece\u800c\u907f\u514d\u4e00\u6b21\u5360\u7528\u5927\u91cf\u5185\u5b58\u3002\u4f7f\u7528\u6d41\u5f0f\u89e3\u6790\u53ef\u4ee5\u663e\u8457\u51cf\u8f7b\u5185\u5b58\u8d1f\u62c5\uff0c\u7279\u522b\u662f\u5bf9\u4e8e\u90a3\u4e9b\u6709\u6df1\u5d4c\u5957\u7ed3\u6784\u6216\u5305\u542b\u5927\u91cf\u6570\u636e\u7684JSON\u6587\u4ef6\u6765\u8bf4\u5c24\u4e3a\u6709\u6548\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528\u6d41\u5f0f\u89e3\u6790\u5904\u7406\u5927\u578bJSON\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u6d41\u5f0f\u89e3\u6790\u80fd\u6709\u6548\u964d\u4f4e\u5185\u5b58\u5360\u7528\uff0c\u5e76\u63d0\u4f9b\u5bf9\u5927\u578b\u6570\u636e\u7684\u8fde\u7eed\u5904\u7406\u80fd\u529b\u3002\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>ijson<\/code>\u5e93\u6765\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\u3002\u9996\u5148\u9700\u8981\u5b89\u88c5<code>ijson<\/code>\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-shell\">pip install ijson<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u6309\u5982\u4e0b\u65b9\u5f0f\u4f7f\u7528<code>ijson<\/code>\u8fdb\u884c\u6d41\u5f0f\u89e3\u6790\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import ijson<\/p>\n<p>filename = &quot;your_large_file.json&quot;<\/p>\n<p>with open(filename, &#039;rb&#039;) as f:<\/p>\n<p>    objects = ijson.items(f, &#039;item&#039;)<\/p>\n<p>    for obj in objects:<\/p>\n<p>        # \u5904\u7406\u6bcf\u4e00\u4e2aJSON\u5bf9\u8c61<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u6b64\u4ee3\u7801\u4e2d\uff0c<code>ijson.items<\/code>\u51fd\u6570\u4ee5\u6d41\u7684\u5f62\u5f0f\u8fd4\u56de\u4e00\u4e2a\u751f\u6210\u5668\uff0c\u904d\u5386\u8be5\u751f\u6210\u5668\u65f6\u4f1a\u6bcf\u6b21\u751f\u6210\u4e00\u4e2aJSON\u5bf9\u8c61\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u5408\u5904\u7406\u5305\u542b\u591a\u4e2aJSON\u5bf9\u8c61\u7684\u5927\u578b\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u9012\u589e\u5f0f\u89e3\u6790\uff08Incremental Parsing\uff09<\/h3>\n<\/p>\n<p><p>\u9012\u589e\u5f0f\u89e3\u6790\u662f\u53e6\u4e00\u79cd\u8282\u7701\u5185\u5b58\u7684\u6280\u672f\uff0c\u4e0e\u6d41\u5f0f\u89e3\u6790\u76f8\u4f3c\uff0c\u4f46\u66f4\u9002\u7528\u4e8e\u5355\u4e2a\u5927\u578bJSON\u5bf9\u8c61\u3002\u4f7f\u7528Python\u5185\u7f6e\u7684<code>json<\/code>\u5e93\u7684<code>JSONDecoder<\/code>\u7c7b\u53ef\u4ee5\u5b9e\u73b0\u6b64\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import json<\/p>\n<p>def parse_large_json(file_path):<\/p>\n<p>    with open(file_path, &#039;r&#039;) as f:<\/p>\n<p>        decoder = json.JSONDecoder()<\/p>\n<p>        buffer = &#039;&#039;<\/p>\n<p>        for chunk in iter(lambda: f.read(4096), &#039;&#039;):<\/p>\n<p>            buffer += chunk<\/p>\n<p>            while buffer:<\/p>\n<p>                try:<\/p>\n<p>                    obj, idx = decoder.raw_decode(buffer)<\/p>\n<p>                    yield obj<\/p>\n<p>                    buffer = buffer[idx:].lstrip()<\/p>\n<p>                except json.JSONDecodeError:<\/p>\n<p>                    # Not enough data to decode, read more<\/p>\n<p>                    break<\/p>\n<h2><strong>\u4f7f\u7528\u751f\u6210\u5668\u9010\u4e2a\u5904\u7406JSON\u5bf9\u8c61<\/strong><\/h2>\n<p>for obj in parse_large_json(&quot;your_large_file.json&quot;):<\/p>\n<p>    # \u5904\u7406obj<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u901a\u8fc7\u5b9a\u4e49\u4e00\u4e2a\u751f\u6210\u5668\u51fd\u6570<code>parse_large_json<\/code>\uff0c\u53ef\u4ee5\u9010\u5757\u8bfb\u53d6\u6587\u4ef6\u5185\u5bb9\uff0c\u5e76\u5c1d\u8bd5\u9012\u589e\u5f0f\u89e3\u6790JSON\u5bf9\u8c61\uff0c\u4ece\u800c\u8282\u7701\u5185\u5b58\u5360\u7528\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528\u5185\u5b58\u6620\u5c04\u6587\u4ef6\u4f18\u5316\u5185\u5b58\u4f7f\u7528<\/h3>\n<\/p>\n<p><p>\u5185\u5b58\u6620\u5c04\u6587\u4ef6\uff08Memory-mapped file\uff09\u662f\u53e6\u4e00\u79cd\u8bfb\u53d6\u5927\u578b\u6587\u4ef6\u7684\u6709\u6548\u65b9\u5f0f\uff0c\u5c24\u5176\u662f\u5f53\u6587\u4ef6\u5927\u5c0f\u8d85\u51fa\u7cfb\u7edf\u5185\u5b58\u65f6\u3002\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5c06\u6587\u4ef6\u5185\u5bb9\u6620\u5c04\u5230\u5185\u5b58\u5730\u5740\u7a7a\u95f4\uff0c\u4f7f\u5f97\u64cd\u4f5c\u7cfb\u7edf\u8d1f\u8d23\u5206\u9875\u52a0\u8f7d\u6587\u4ef6\u5185\u5bb9\uff0c\u53ea\u6709\u88ab\u8bbf\u95ee\u7684\u90e8\u5206\u624d\u4f1a\u52a0\u8f7d\u5230\u5185\u5b58\u3002<\/p>\n<\/p>\n<p><p>Python\u4e2d\u53ef\u4ee5\u901a\u8fc7<code>mmap<\/code>\u6a21\u5757\u521b\u5efa\u5185\u5b58\u6620\u5c04\u6587\u4ef6\u3002\u7136\u540e\u4f7f\u7528\u524d\u9762\u63d0\u5230\u7684\u6d41\u5f0f\u6216\u9012\u589e\u5f0f\u89e3\u6790\u65b9\u6cd5\uff0c\u6765\u907f\u514d\u6587\u4ef6\u7684\u5168\u90e8\u5185\u5bb9\u4e00\u6b21\u6027\u88ab\u52a0\u8f7d\u5230\u5185\u5b58\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import mmap<\/p>\n<p>import contextlib<\/p>\n<p>with open(&quot;your_large_file.json&quot;, &quot;r+&quot;) as f:<\/p>\n<p>    with contextlib.closing(mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)) as m:<\/p>\n<p>        # \u5728\u6b64\u5904\u53ef\u4ee5\u4f7f\u7528\u9012\u589e\u5f0f\u89e3\u6790\u6216\u6d41\u5f0f\u89e3\u6790\u5904\u7406m<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u4f7f\u7528\u4e86<code>contextlib<\/code>\u7684<code>closing<\/code>\u51fd\u6570\u6765\u786e\u4fdd<code>mmap<\/code>\u5bf9\u8c61\u5728\u4f7f\u7528\u5b8c\u6210\u540e\u6b63\u786e\u5173\u95ed\u3002<\/p>\n<\/p>\n<p><p>\u7efc\u4e0a\u6240\u8ff0\uff0c\u901a\u8fc7\u5408\u9002\u7684\u65b9\u6cd5\u4f18\u5316\u5185\u5b58\u4f7f\u7528\uff0c\u53ef\u4ee5\u6709\u6548\u5904\u7406\u8f83\u5927\u7684JSON\u6587\u4ef6\u5e76\u9632\u6b62\u5f02\u5e38\u53d1\u751f\u3002\u8bb0\u5f97\u8003\u8651\u6570\u636e\u7684\u5177\u4f53\u7ed3\u6784\u548c\u5e94\u7528\u573a\u666f\u6765\u9009\u62e9\u6700\u5408\u9002\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>1. \u5982\u4f55\u5904\u7406Python\u89e3\u6790\u8f83\u5927\u7684JSON\u6587\u4ef6\u62a5\u5f02\u5e38\u7684\u95ee\u9898\uff1f<\/strong><\/p>\n<p>\u5f53\u89e3\u6790\u8f83\u5927\u7684JSON\u6587\u4ef6\u65f6\uff0cPython\u53ef\u80fd\u4f1a\u62a5\u51fa\u5185\u5b58\u9519\u8bef\u6216\u89e3\u6790\u9519\u8bef\u7684\u5f02\u5e38\u3002\u4e3a\u4e86\u5904\u7406\u8fd9\u4e2a\u95ee\u9898\uff0c\u4f60\u53ef\u4ee5\u5c1d\u8bd5\u4ee5\u4e0b\u51e0\u4e2a\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<ul>\n<li><strong>\u5206\u5757\u89e3\u6790JSON\u6587\u4ef6<\/strong>\uff1a\u6211\u4eec\u53ef\u4ee5\u5c06\u8f83\u5927\u7684JSON\u6587\u4ef6\u5206\u6210\u8f83\u5c0f\u7684\u5757\uff0c\u5e76\u9010\u5757\u8fdb\u884c\u89e3\u6790\u3002\u8fd9\u6837\u53ef\u4ee5\u51cf\u5c11\u5185\u5b58\u7684\u5360\u7528\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528json\u6a21\u5757\u7684<code>json.load()<\/code>\u65b9\u6cd5\uff0c\u5e76\u7ed3\u5408\u6587\u4ef6\u7684<code>read()<\/code>\u65b9\u6cd5\uff0c\u9010\u5757\u8bfb\u53d6\u548c\u89e3\u6790JSON\u6570\u636e\u3002<\/li>\n<li><strong>\u4f7f\u7528\u5e26\u6709\u7f13\u51b2\u533a\u7684\u8bfb\u53d6<\/strong>\uff1a\u5728\u8bfb\u53d6JSON\u6587\u4ef6\u65f6\uff0c\u4f7f\u7528\u5e26\u6709\u7f13\u51b2\u533a\u7684\u8bfb\u53d6\u65b9\u5f0f\uff0c\u53ef\u4ee5\u51cf\u5c11\u5185\u5b58\u7684\u5360\u7528\u3002<\/li>\n<li><strong>\u4f7f\u7528\u5176\u4ed6\u7684JSON\u89e3\u6790\u5e93<\/strong>\uff1a\u9664\u4e86Python\u5185\u7f6e\u7684json\u6a21\u5757\uff0c\u8fd8\u6709\u5176\u4ed6\u7684\u7b2c\u4e09\u65b9\u5e93\u53ef\u4ee5\u7528\u4e8e\u89e3\u6790JSON\u6587\u4ef6\uff0c\u4f8b\u5982<code>ijson<\/code>\u548c<code>jsonlines<\/code>\u3002\u8fd9\u4e9b\u5e93\u53ef\u4ee5\u66f4\u6709\u6548\u5730\u5904\u7406\u8f83\u5927\u7684JSON\u6587\u4ef6\uff0c\u5e76\u63d0\u4f9b\u4e86\u66f4\u7075\u6d3b\u7684\u89e3\u6790\u9009\u9879\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u4e9b\u89e3\u51b3\u65b9\u6848\u53ef\u4ee5\u5e2e\u52a9\u4f60\u6709\u6548\u5730\u5904\u7406\u89e3\u6790\u8f83\u5927\u7684JSON\u6587\u4ef6\u62a5\u5f02\u5e38\u7684\u95ee\u9898\u3002<\/p>\n<hr>\n<p><strong>2. \u5982\u4f55\u5904\u7406Python\u89e3\u6790\u5927\u578bJSON\u6587\u4ef6\u65f6\u7684\u6027\u80fd\u95ee\u9898\uff1f<\/strong><\/p>\n<p>\u5f53\u5904\u7406\u5927\u578bJSON\u6587\u4ef6\u65f6\uff0cPython\u53ef\u80fd\u4f1a\u9762\u4e34\u6027\u80fd\u74f6\u9888\u7684\u95ee\u9898\u3002\u4e3a\u4e86\u63d0\u9ad8\u6027\u80fd\uff0c\u53ef\u4ee5\u8003\u8651\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li><strong>\u4f7f\u7528\u6d41\u5f0f\u5904\u7406<\/strong>\uff1a\u4f7f\u7528\u6d41\u5f0f\u5904\u7406\u53ef\u4ee5\u4e00\u8fb9\u8bfb\u53d6JSON\u6587\u4ef6\u4e00\u8fb9\u8fdb\u884c\u89e3\u6790\uff0c\u800c\u4e0d\u662f\u5c06\u6574\u4e2a\u6587\u4ef6\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u3002\u8fd9\u53ef\u4ee5\u5927\u5927\u51cf\u5c11\u5185\u5b58\u7684\u5360\u7528\uff0c\u63d0\u9ad8\u89e3\u6790\u901f\u5ea6\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528<code>json.JSONDecoder()<\/code>\u7c7b\u7684<code>raw_decode()<\/code>\u65b9\u6cd5\uff0c\u9010\u884c\u8bfb\u53d6\u6587\u4ef6\u5e76\u89e3\u6790JSON\u6570\u636e\u3002<\/li>\n<li><strong>\u538b\u7f29JSON\u6587\u4ef6<\/strong>\uff1a\u5982\u679c\u53ef\u80fd\u7684\u8bdd\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u538b\u7f29\u7b97\u6cd5\u6765\u51cf\u5c0fJSON\u6587\u4ef6\u7684\u5927\u5c0f\u3002\u538b\u7f29\u6587\u4ef6\u540e\uff0cPython\u89e3\u6790JSON\u7684\u901f\u5ea6\u4f1a\u66f4\u5feb\u3002<\/li>\n<li><strong>\u4f18\u5316\u6570\u636e\u7ed3\u6784<\/strong>\uff1a\u5728\u89e3\u6790JSON\u6587\u4ef6\u540e\uff0c\u4f60\u53ef\u4ee5\u8003\u8651\u5c06\u6570\u636e\u8f6c\u6362\u4e3a\u66f4\u9ad8\u6548\u7684\u6570\u636e\u7ed3\u6784\uff0c\u4f8b\u5982\u5b57\u5178\u6216\u96c6\u5408\u3002\u8fd9\u6837\u53ef\u4ee5\u51cf\u5c0f\u5185\u5b58\u7684\u5360\u7528\uff0c\u5e76\u63d0\u9ad8\u5904\u7406\u901f\u5ea6\u3002<\/li>\n<li><strong>\u5e76\u884c\u5904\u7406<\/strong>\uff1a\u5982\u679c\u4f60\u7684\u673a\u5668\u5177\u5907\u591a\u6838\u5904\u7406\u80fd\u529b\uff0c\u4f60\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u5e76\u884c\u5904\u7406\u6765\u52a0\u901f\u89e3\u6790\u5927\u578bJSON\u6587\u4ef6\u3002\u53ef\u4ee5\u4f7f\u7528Python\u7684\u5e76\u884c\u5904\u7406\u5e93\uff0c\u4f8b\u5982<code>multiprocessing<\/code>\u6216<code>concurrent.futures<\/code>\u3002<\/li>\n<\/ul>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u65b9\u6cd5\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u5904\u7406Python\u89e3\u6790\u5927\u578bJSON\u6587\u4ef6\u65f6\u7684\u6027\u80fd\u95ee\u9898\u3002<\/p>\n<hr>\n<p><strong>3. \u5982\u4f55\u4f18\u5316Python\u7a0b\u5e8f\u89e3\u6790JSON\u6587\u4ef6\u7684\u6548\u7387\uff1f<\/strong><\/p>\n<p>\u5982\u679c\u4f60\u60f3\u4f18\u5316Python\u7a0b\u5e8f\u89e3\u6790JSON\u6587\u4ef6\u7684\u6548\u7387\uff0c\u53ef\u4ee5\u8003\u8651\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u9762\uff1a<\/p>\n<ul>\n<li><strong>\u907f\u514d\u91cd\u590d\u89e3\u6790<\/strong>\uff1a\u5982\u679c\u4f60\u9700\u8981\u591a\u6b21\u89e3\u6790\u540c\u4e00\u4e2aJSON\u6587\u4ef6\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u5c06\u89e3\u6790\u7ed3\u679c\u7f13\u5b58\u8d77\u6765\uff0c\u907f\u514d\u91cd\u590d\u89e3\u6790\u3002\u8fd9\u6837\u53ef\u4ee5\u51cf\u5c11\u89e3\u6790\u65f6\u95f4\uff0c\u63d0\u9ad8\u6548\u7387\u3002\u53ef\u4ee5\u5c06\u89e3\u6790\u7ed3\u679c\u4fdd\u5b58\u5728\u53d8\u91cf\u4e2d\uff0c\u6216\u8005\u4f7f\u7528\u7f13\u5b58\u5e93\uff0c\u4f8b\u5982<code>functools.lru_cache<\/code>\u3002<\/li>\n<li><strong>\u9009\u62e9\u5408\u9002\u7684\u89e3\u6790\u65b9\u5f0f<\/strong>\uff1a\u6839\u636eJSON\u6587\u4ef6\u7684\u7279\u70b9\u548c\u9700\u6c42\uff0c\u9009\u62e9\u5408\u9002\u7684\u89e3\u6790\u65b9\u5f0f\u3002\u5982\u679c\u53ea\u9700\u8981\u83b7\u53d6\u90e8\u5206\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528\u57fa\u4e8e\u4e8b\u4ef6\u7684\u89e3\u6790\u65b9\u5f0f\uff0c\u5982<code>json.JSONDecoder()<\/code>\u7c7b\u7684<code>raw_decode()<\/code>\u65b9\u6cd5\uff1b\u5982\u679c\u9700\u8981\u8bbf\u95ee\u6574\u4e2aJSON\u6587\u4ef6\u7684\u6240\u6709\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528\u57fa\u4e8e\u5bf9\u8c61\u7684\u89e3\u6790\u65b9\u5f0f\uff0c\u5982<code>json.load()<\/code>\u6216<code>json.loads()<\/code>\u65b9\u6cd5\u3002<\/li>\n<li><strong>\u4f7f\u7528\u8f83\u65b0\u7248\u672c\u7684Python<\/strong>\uff1aPython\u7684\u6bcf\u4e2a\u7248\u672c\u90fd\u4f1a\u5bf9\u89e3\u6790JSON\u6587\u4ef6\u7684\u6027\u80fd\u8fdb\u884c\u6539\u8fdb\u3002\u4f7f\u7528\u8f83\u65b0\u7248\u672c\u7684Python\u53ef\u80fd\u4f1a\u6709\u66f4\u597d\u7684\u89e3\u6790\u6027\u80fd\u3002\u5982\u679c\u53ef\u80fd\u7684\u8bdd\uff0c\u5efa\u8bae\u4f7f\u7528Python 3.x\u7684\u6700\u65b0\u7248\u672c\u3002<\/li>\n<li><strong>\u51cf\u5c0fJSON\u6587\u4ef6\u7684\u5927\u5c0f<\/strong>\uff1a\u5982\u679c\u53ef\u80fd\u7684\u8bdd\uff0c\u53ef\u4ee5\u5c06JSON\u6587\u4ef6\u4e2d\u7684\u6570\u636e\u8fdb\u884c\u538b\u7f29\u6216\u4f18\u5316\uff0c\u51cf\u5c0f\u6587\u4ef6\u7684\u5927\u5c0f\u3002\u5728\u51cf\u5c0f\u6587\u4ef6\u6240\u9700\u7684\u89e3\u6790\u65f6\u95f4\u65b9\u9762\u4f1a\u6709\u4e00\u5b9a\u7684\u5e2e\u52a9\u3002<\/li>\n<\/ul>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u4f18\u5316\u65b9\u6cd5\uff0c\u53ef\u4ee5\u63d0\u9ad8Python\u7a0b\u5e8f\u89e3\u6790JSON\u6587\u4ef6\u7684\u6548\u7387\uff0c\u8ba9\u7a0b\u5e8f\u8fd0\u884c\u66f4\u52a0\u9ad8\u6548\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728\u5904\u7406\u8f83\u5927\u7684JSON\u6587\u4ef6\u65f6\uff0c\u5e38\u89c1\u7684\u5f02\u5e38\u5305\u62ec\u5185\u5b58\u6ea2\u51fa\u3001\u89e3\u6790\u65f6\u95f4\u8fc7\u957f\u3001\u89e3\u6790\u9519\u8bef\u7b49\u3002\u89e3\u51b3\u8fd9\u4e9b\u5f02\u5e38\u7684\u65b9\u6cd5\u4e3b\u8981\u6709\uff1a\u4f7f\u7528\u6d41 [&hellip;]","protected":false},"author":3,"featured_media":176923,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/176910"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=176910"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/176910\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/176923"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=176910"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=176910"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=176910"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}