{"id":205145,"date":"2025-05-29T09:36:29","date_gmt":"2025-05-29T01:36:29","guid":{"rendered":"https:\/\/server.hk\/cnblog\/205145\/"},"modified":"2025-05-29T09:36:29","modified_gmt":"2025-05-29T01:36:29","slug":"python%e5%a6%82%e4%bd%95%e4%bb%a5%e6%a0%91%e7%8a%b6%e7%bb%93%e6%9e%84%e6%89%93%e5%8d%b0%e5%a4%9a%e5%b1%82%e5%b5%8c%e5%a5%97json%e6%95%b0%e6%8d%ae%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/205145\/","title":{"rendered":"Python\u5982\u4f55\u4ee5\u6811\u72b6\u7ed3\u6784\u6253\u5370\u591a\u5c42\u5d4c\u5957JSON\u6570\u636e\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Python\u5982\u4f55\u4ee5\u6811\u72b6\u7ed3\u6784\u6253\u5370\u591a\u5c42\u5d4c\u5957JSON\u6570\u636e\uff1f<\/h1>\n<p>\u6587\u7ae0\u5c0f\u767d\u4e00\u679a\uff0c\u6b63\u5728\u4e0d\u65ad\u5b66\u4e60\u79ef\u7d2f\u77e5\u8bc6\uff0c\u73b0\u5c06\u5b66\u4e60\u5230\u7684\u77e5\u8bc6\u8bb0\u5f55\u4e00\u4e0b\uff0c\u4e5f\u662f\u5c06\u6211\u7684\u6240\u5f97\u5206\u4eab\u7ed9\u5927\u5bb6\uff01\u800c\u4eca\u5929\u8fd9\u7bc7\u6587\u7ae0\u300aPython\u5982\u4f55\u4ee5\u6811\u72b6\u7ed3\u6784\u6253\u5370\u591a\u5c42\u5d4c\u5957JSON\u6570\u636e\uff1f\u300b\u5e26\u5927\u5bb6\u6765\u4e86\u89e3\u4e00\u4e0b##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u4ece\u800c\u5f25\u8865\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241124\/173244423267430048a66fb.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u5982\u4f55\u7528 python \u904d\u5386 n \u7ea7 json \u5e76\u4ee5\u6811\u72b6\u6253\u5370<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong><\/p>\n<p>\u5982\u4f55\u904d\u5386\u5e76\u5168\u91cf\u6253\u5370\u5982\u4e0b json \u6570\u636e\u4e2d\u7684\u6240\u6709\u8282\u70b9\uff0c\u4f7f\u5176\u5448\u73b0\u6811\u72b6\u7ed3\u6784\uff1f<\/p>\n<pre>{\n  \"id\": \"series\",\n  \"css\": \"wrapper\",\n  \"html\": [\n    {\n      \"id\": \"series\",\n      \"css\": \"header\",\n      \"html\": [\n        {\n          \"css\": \"topbar\",\n          \"html\": [\n            {\n              \"css\": \"left\",\n              \"html\": []\n            },\n            {\n              \"css\": \"middle\",\n              \"html\": []\n            },\n            {\n              \"css\": \"right\",\n              \"html\": []\n            }\n          ]\n        },\n        {\n          \"css\": \"mask\",\n          \"html\": []\n        },\n        {\n          \"css\": \"layer\",\n          \"html\": []\n        }\n      ]\n    },\n    {\n      \"id\": \"series\",\n      \"css\": \"container\",\n      \"html\": [\n        {\n          \"id\": \"series\",\n          \"css\": \"container ad1200 mt10\",\n          \"html\": []\n        },\n        {\n          \"id\": \"series\",\n          \"css\": \"container crumb\",\n          \"html\": []\n        },\n        {\n          \"id\": \"series\",\n          \"css\": \"container nav\",\n          \"html\": []\n        },\n        {\n          \"id\": \"series\",\n          \"css\": \"series_wrapper\",\n          \"html\": [\n            {\n              \"id\": \"series\",\n              \"css\": \"main\",\n              \"html\": [\n                {\n                  \"pic\": \"\",\n                  \"total\": \"\"\n                },\n                {\n                  \"news1\": \"\",\n                  \"new2\": \"\"\n                },\n                {\n                  \"ad1\": \"\"\n                },\n                {\n                  \"list\": \"\"\n                },\n                {\n                  \"pic\": \"\"\n                },\n                {\n                  \"video\": \"\"\n                },\n                {\n                  \"ad2\": \"\"\n                }\n              ]\n            },\n            {\n              \"id\": \"series\",\n              \"css\": \"side\",\n              \"html\": [\n                {\n                  \"ad3\": \"google\"\n                },\n                {\n                  \"love\": \"\"\n                },\n                {\n                  \"brand\": \"\"\n                },\n                {\n                  \"type\": \"\"\n                }\n              ]\n            }\n          ]\n        }\n      ]\n    },\n    {\n      \"position\": [\n        {\n          \"return_top\": \"\"\n        },\n        {\n          \"side_nav\": \"\"\n        }\n      ]\n    },\n    {\n      \"footer\": [\n        {\n          \"nav\": \"\"\n        }\n      ]\n    }\n  ]\n}<\/pre>\n<p><strong>\u56de\u7b54\uff1a<\/strong><\/p>\n<p>\u8981\u904d\u5386 n \u7ea7 json \u5e76\u4ee5\u6811\u72b6\u6253\u5370\u5176\u6240\u6709\u8282\u70b9\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b python \u51fd\u6570\uff1a<\/p>\n<pre>def print_json_tree(json_obj, indent=0):\n    if isinstance(json_obj, dict):\n        for key, value in json_obj.items():\n            print('-' * indent + str(key))\n            print_json_tree(value, indent+2)\n    elif isinstance(json_obj, list):\n        for item in json_obj:\n            print_json_tree(item, indent+2)\n    else:\n        print('-' * indent + str(json_obj))<\/pre>\n<p>\u8be5\u51fd\u6570\u4ee5\u9012\u5f52\u7684\u65b9\u5f0f\u904d\u5386 json \u5bf9\u8c61\uff0c\u4f7f\u7528\u7f29\u8fdb\u5b57\u7b26\uff08-\uff09\u6765\u8868\u793a\u4e0d\u540c\u7684\u5c42\u7ea7\u3002\u5177\u4f53\u8fc7\u7a0b\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>\u5982\u679c\u5f53\u524d\u5bf9\u8c61\u662f\u5b57\u5178\uff08dict\uff09\uff0c\u904d\u5386\u5176\u952e\u548c\u503c\uff0c\u5e76\u5c06\u503c\u4f5c\u4e3a\u65b0\u7684\u4e00\u5c42\u8fdb\u884c\u904d\u5386\u3002<\/li>\n<li>\u5982\u679c\u5f53\u524d\u5bf9\u8c61\u662f\u5217\u8868\uff08list\uff09\uff0c\u904d\u5386\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\uff0c\u5e76\u5c06\u5143\u7d20\u4f5c\u4e3a\u65b0\u7684\u4e00\u5c42\u8fdb\u884c\u904d\u5386\u3002<\/li>\n<li>\u5982\u679c\u5f53\u524d\u5bf9\u8c61\u662f\u6807\u91cf\u7c7b\u578b\uff08\u5b57\u7b26\u4e32\u3001\u6574\u6570\u3001\u6d6e\u70b9\u6570\u7b49\uff09\uff0c\u5219\u76f4\u63a5\u6253\u5370\u51fa\u6765\u3002<\/li>\n<\/ol>\n<p>\u901a\u8fc7\u8c03\u7528\u6b64\u51fd\u6570\uff0c\u53ef\u4ee5\u4ee5\u6811\u72b6\u683c\u5f0f\u904d\u5386\u5e76\u6253\u5370 json \u5bf9\u8c61\u7684\u5168\u90e8\u5185\u5bb9\u3002<\/p>\n<p>\u672c\u7bc7\u5173\u4e8e\u300aPython\u5982\u4f55\u4ee5\u6811\u72b6\u7ed3\u6784\u6253\u5370\u591a\u5c42\u5d4c\u5957JSON\u6570\u636e\uff1f\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python\u5982\u4f55\u4ee5\u6811\u72b6\u7ed3\u6784\u6253\u5370\u591a&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-205145","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205145","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=205145"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205145\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=205145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=205145"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=205145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}