{"id":50220,"date":"2024-12-03T17:03:12","date_gmt":"2024-12-03T09:03:12","guid":{"rendered":"https:\/\/fwq.ai\/blog\/50220\/"},"modified":"2024-12-03T17:03:12","modified_gmt":"2024-12-03T09:03:12","slug":"%e5%a6%82%e4%bd%95%e5%b0%86-python-%e4%b8%ad%e7%9a%84%e5%ad%97%e7%ac%a6%e4%b8%b2%e8%bd%ac%e6%8d%a2%e6%88%90%e5%8c%85%e5%90%ab%e5%ad%97%e5%85%b8%e7%9a%84%e5%88%97%e8%a1%a8%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/50220\/","title":{"rendered":"\u5982\u4f55\u5c06 Python \u4e2d\u7684\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u5305\u542b\u5b57\u5178\u7684\u5217\u8868\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u5c06 Python \u4e2d\u7684\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u5305\u542b\u5b57\u5178\u7684\u5217\u8868\uff1f<\/h1>\n<p>IT\u884c\u4e1a\u76f8\u5bf9\u4e8e\u4e00\u822c\u4f20\u7edf\u884c\u4e1a\uff0c\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u66f4\u5feb\uff0c\u4e00\u65e6\u505c\u6b62\u4e86\u5b66\u4e60\uff0c\u5f88\u5feb\u5c31\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u6240\u4ee5\u6211\u4eec\u9700\u8981\u8e0f\u8e0f\u5b9e\u5b9e\u7684\u4e0d\u65ad\u5b66\u4e60\uff0c\u7cbe\u8fdb\u81ea\u5df1\u7684\u6280\u672f\uff0c\u5c24\u5176\u662f\u521d\u5b66\u8005\u3002\u4eca\u5929\u7c73\u4e91\u7ed9\u5927\u5bb6\u6574\u7406\u4e86\u300a\u5982\u4f55\u5c06 Python \u4e2d\u7684\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u5305\u542b\u5b57\u5178\u7684\u5217\u8868\uff1f\u300b\uff0c\u804a\u804a\uff0c\u6211\u4eec\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241114\/17315814796735d6273e0be.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5c06 Python \u4e2d\u7684\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u5305\u542b\u5b57\u5178\u7684\u5217\u8868\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5c06 Python \u4e2d\u7684\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u5305\u542b\u5b57\u5178\u7684\u5217\u8868\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5728 python \u4e2d\u8f6c\u6362 string \u4e3a list[dicts]<\/strong><\/p>\n<p>\u60a8\u9700\u8981\u5c06\u4e00\u4e2a string \u8f6c\u6362\u6210\u4e00\u4e2a\u5305\u542b\u5b57\u5178\u7684 list\u3002\u4e3a\u6b64\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li><strong>json \u89e3\u6790\uff1a<\/strong> \u4f7f\u7528 json \u6a21\u5757\u4e2d\u7684 json.loads() \u51fd\u6570\uff0c\u8be5\u51fd\u6570\u5c06 json \u5b57\u7b26\u4e32\u89e3\u6790\u4e3a python \u5b57\u5178\u3002<\/li>\n<li><strong>\u7c7b\u578b\u8f6c\u6362\uff1a<\/strong> json.loads() \u51fd\u6570\u8fd4\u56de\u4e00\u4e2a python \u5b57\u5178\u3002\u8981\u5c06\u5176\u8f6c\u6362\u4e3a list[dicts]\uff0c\u8bf7\u4f7f\u7528\u65b9\u62ec\u53f7 [] \u5c06\u5b83\u5c01\u88c5\u8d77\u6765\u3002<\/li>\n<\/ol>\n<p>\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<pre>import json\n\nstr_content = '''\n[\n{\n\"id\": \"failure\",\n\"description\": null,\n\"event\": [],\n\"rowid\": 1\n},\n{\n\"id\": \"virtual\",\n\"description\": null,\n\"event\": [],\n\"rowid\": 2\n},\n{\n\"id\": \"cleaning\",\n\"description\": null,\n\"event\": [],\n\"rowid\": 3\n}\n]\n'''\n\nexpected_result_converted = json.loads(str_content)\nprint(expected_result_converted)<\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre>[{'Id': 'Failure', 'Description': None, 'Event': [], 'RowId': 1},\n {'Id': 'Virtual', 'Description': None, 'Event': [], 'RowId': 2},\n {'Id': 'Cleaning', 'Description': None, 'Event': [], 'RowId': 3}]<\/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\u300a\u5982\u4f55\u5c06 Python \u4e2d\u7684\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u5305\u542b\u5b57\u5178\u7684\u5217\u8868\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>\u5982\u4f55\u5c06 Python \u4e2d\u7684\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u5305\u542b\u5b57\u5178\u7684\u5217\u8868\uff1f IT\u884c\u4e1a\u76f8\u5bf9\u4e8e\u4e00\u822c\u4f20\u7edf\u884c\u4e1a\uff0c\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u66f4\u5feb\uff0c\u4e00\u65e6\u505c\u6b62\u4e86\u5b66\u4e60\uff0c\u5f88\u5feb\u5c31\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u6240\u4ee5\u6211\u4eec\u9700\u8981\u8e0f\u8e0f\u5b9e\u5b9e\u7684\u4e0d\u65ad\u5b66\u4e60\uff0c\u7cbe\u8fdb\u81ea\u5df1\u7684\u6280\u672f\uff0c\u5c24\u5176\u662f\u521d\u5b66\u8005\u3002\u4eca\u5929\u7c73\u4e91\u7ed9\u5927\u5bb6\u6574\u7406\u4e86\u300a\u5982\u4f55\u5c06 Python \u4e2d\u7684\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u5305\u542b\u5b57\u5178\u7684\u5217\u8868\uff1f\u300b\uff0c\u804a\u804a\uff0c\u6211\u4eec\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01 \u5728 python \u4e2d\u8f6c\u6362 string \u4e3a list[dicts] \u60a8\u9700\u8981\u5c06\u4e00\u4e2a string \u8f6c\u6362\u6210\u4e00\u4e2a\u5305\u542b\u5b57\u5178\u7684 list\u3002\u4e3a\u6b64\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a json \u89e3\u6790\uff1a \u4f7f\u7528 json \u6a21\u5757\u4e2d\u7684 json.loads() \u51fd\u6570\uff0c\u8be5\u51fd\u6570\u5c06 json \u5b57\u7b26\u4e32\u89e3\u6790\u4e3a python \u5b57\u5178\u3002 \u7c7b\u578b\u8f6c\u6362\uff1a json.loads() \u51fd\u6570\u8fd4\u56de\u4e00\u4e2a python \u5b57\u5178\u3002\u8981\u5c06\u5176\u8f6c\u6362\u4e3a list[dicts]\uff0c\u8bf7\u4f7f\u7528\u65b9\u62ec\u53f7 [] \u5c06\u5b83\u5c01\u88c5\u8d77\u6765\u3002 \u793a\u4f8b\u4ee3\u7801\uff1a import json str_content = &#8221;&#8217; [ { &#8220;id&#8221;: &#8220;failure&#8221;, &#8220;description&#8221;: null, &#8220;event&#8221;: [], &#8220;rowid&#8221;: 1 }, { &#8220;id&#8221;: &#8220;virtual&#8221;, [&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-50220","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/50220","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=50220"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/50220\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=50220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=50220"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=50220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}