{"id":204196,"date":"2025-05-29T10:34:51","date_gmt":"2025-05-29T02:34:51","guid":{"rendered":"https:\/\/server.hk\/cnblog\/204196\/"},"modified":"2025-05-29T10:34:51","modified_gmt":"2025-05-29T02:34:51","slug":"%e5%a6%82%e4%bd%95%e4%bb%8e%e6%96%87%e6%9c%ac%e6%96%87%e4%bb%b6%e4%b8%ad%e8%af%bb%e5%8f%96%e5%ad%97%e5%85%b8%e6%a0%bc%e5%bc%8f%e7%9a%84%e6%95%b0%e6%8d%ae%e5%b9%b6%e8%bd%ac%e6%8d%a2%e6%a0%bc%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/204196\/","title":{"rendered":"\u5982\u4f55\u4ece\u6587\u672c\u6587\u4ef6\u4e2d\u8bfb\u53d6\u5b57\u5178\u683c\u5f0f\u7684\u6570\u636e\u5e76\u8f6c\u6362\u683c\u5f0f\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u4ece\u6587\u672c\u6587\u4ef6\u4e2d\u8bfb\u53d6\u5b57\u5178\u683c\u5f0f\u7684\u6570\u636e\u5e76\u8f6c\u6362\u683c\u5f0f\uff1f<\/h1>\n<p>\u4eca\u5929\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u8bf7\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427\uff01\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u662f\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u6216\u8005\u5df2\u7ecf\u662f\u5927\u4f6c\u7ea7\u522b\u4e86\uff0c\u90fd\u975e\u5e38\u6b22\u8fce\u4e5f\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u7ed9\u6211\u5efa\u8bae\u8bc4\u8bba\u54c8~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241031\/173037874667237bfae21d1.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u4ece\u6587\u672c\u8bfb\u53d6\u5b57\u5178\u683c\u5f0f\u6570\u636e<\/strong><\/p>\n<p>\u672c\u6587\u4ecb\u7ecd\u4e86\u5982\u4f55\u4ece\u6587\u672c\u6587\u4ef6\u4e2d\u8bfb\u53d6\u5b57\u5178\u683c\u5f0f\u7684\u6570\u636e\uff0c\u5e76\u5c06\u6570\u636e\u8f6c\u6362\u6210\u6307\u5b9a\u683c\u5f0f\u3002<\/p>\n<p>\u6587\u672c\u4e2d\u7684\u6570\u636e\u91c7\u7528\u5b57\u5178\u683c\u5f0f\uff0c\u5176\u4e2d\u952e\u503c\u5bf9\u7528\u5355\u5f15\u53f7\u62ec\u4f4f\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<pre>{'command': 'cmd1', 'option': [{'req': [{'ipt': [{'str1': 'name1'}]}]}], 'os': 'os1', 'device': 'd1'}<\/pre>\n<p>\u800c\u6211\u4eec\u9700\u8981\u5c06\u5176\u8f6c\u6362\u6210\u5982\u4e0b\u683c\u5f0f\uff1a<\/p>\n<pre>cmd1 name1 os1 d1\ncmd2 name2 os2 d2\ncmd3 name3_1 os2 d3\ncmd3 name3_2 os2 d3\ncmd3 name3_3 os2 d3<\/pre>\n<p>\u5176\u4e2d\uff0coption\u5143\u7d20\u5305\u542b\u591a\u4e2a\u5143\u7d20\u65f6\uff0c\u4f1a\u5206\u6210\u591a\u884c\u3002<\/p>\n<p>\u539f\u672c\u6253\u7b97\u5229\u7528\u6587\u672c\u4e2d\u5df2\u7ecf\u6210\u578b\u7684\u5b57\u5178\u683c\u5f0f\uff0c\u4f46\u8bfb\u53d6\u6587\u672c\u65f6\u5374\u5f97\u5230\u4e86\u5b57\u7b26\u4e32\u5f62\u5f0f\u7684\u6570\u636e\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5<\/strong><\/p>\n<p>\u5b9e\u9645\u4e0a\uff0c\u6587\u672c\u4e2d\u7684\u683c\u5f0f\u5df2\u7ecf\u975e\u5e38\u63a5\u8fd1 json \u683c\u5f0f\uff0c\u53ea\u9700\u5c06\u6587\u672c\u4e2d\u7684\u5355\u5f15\u53f7\u66ff\u6362\u4e3a\u53cc\u5f15\u53f7\uff0c\u7136\u540e\u518d\u4f7f\u7528 json.loads \u51fd\u6570\u52a0\u8f7d\u5373\u53ef\u3002<\/p>\n<p>\u5b8c\u6574\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>import json\n\ncontent = None\nwith open('data.txt', 'r', encoding='utf-8') as file:\n    content = file.read()\n\ncontent = content.replace(\"'\", '\"')\ndata = json.loads(content)<\/pre>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300a\u5982\u4f55\u4ece\u6587\u672c\u6587\u4ef6\u4e2d\u8bfb\u53d6\u5b57\u5178\u683c\u5f0f\u7684\u6570\u636e\u5e76\u8f6c\u6362\u683c\u5f0f\uff1f\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8\u516c\u4f17\u53f7\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4ece\u6587\u672c\u6587\u4ef6\u4e2d\u8bfb\u53d6\u5b57\u5178\u683c\u5f0f\u7684\u6570&#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-204196","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204196","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=204196"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204196\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=204196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=204196"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=204196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}