{"id":50005,"date":"2024-12-03T10:48:01","date_gmt":"2024-12-03T02:48:01","guid":{"rendered":"https:\/\/fwq.ai\/blog\/50005\/"},"modified":"2024-12-03T10:48:01","modified_gmt":"2024-12-03T02:48:01","slug":"%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9%e4%bb%a3%e7%a0%81%e9%81%bf%e5%85%8d%e7%85%a7%e7%89%87%e5%92%8c%e8%a7%86%e9%a2%91%e6%96%87%e4%bb%b6%e8%a2%ab%e5%a4%8d%e5%88%b6%e5%88%b0%e5%90%8c%e4%b8%80%e4%b8%aa","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/50005\/","title":{"rendered":"\u5982\u4f55\u4fee\u6539\u4ee3\u7801\u907f\u514d\u7167\u7247\u548c\u89c6\u9891\u6587\u4ef6\u88ab\u590d\u5236\u5230\u540c\u4e00\u4e2a\u6587\u4ef6\u5939\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u4fee\u6539\u4ee3\u7801\u907f\u514d\u7167\u7247\u548c\u89c6\u9891\u6587\u4ef6\u88ab\u590d\u5236\u5230\u540c\u4e00\u4e2a\u6587\u4ef6\u5939\uff1f<\/h1>\n<p>\u77e5\u8bc6\u70b9\u638c\u63e1\u4e86\uff0c\u8fd8\u9700\u8981\u4e0d\u65ad\u7ec3\u4e60\u624d\u80fd\u719f\u7ec3\u8fd0\u7528\u3002\u4e0b\u9762\u7c73\u4e91\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u4e2a\u6587\u7ae0\u5f00\u53d1\u5b9e\u6218\uff0c\u624b\u628a\u624b\u6559\u5927\u5bb6\u5b66\u4e60\u300a\u5982\u4f55\u4fee\u6539\u4ee3\u7801\u907f\u514d\u7167\u7247\u548c\u89c6\u9891\u6587\u4ef6\u88ab\u590d\u5236\u5230\u540c\u4e00\u4e2a\u6587\u4ef6\u5939\uff1f\u300b\uff0c\u5728\u5b9e\u73b0\u529f\u80fd\u7684\u8fc7\u7a0b\u4e2d\u4e5f\u5e26\u5927\u5bb6\u91cd\u65b0\u6e29\u4e60\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6e29\u6545\u800c\u77e5\u65b0\uff0c\u56de\u5934\u770b\u770b\u8bf4\u4e0d\u5b9a\u53c8\u6709\u4e0d\u4e00\u6837\u7684\u611f\u609f\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241109\/1731142850672f24c22e72e.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4fee\u6539\u4ee3\u7801\u907f\u514d\u7167\u7247\u548c\u89c6\u9891\u6587\u4ef6\u88ab\u590d\u5236\u5230\u540c\u4e00\u4e2a\u6587\u4ef6\u5939\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4fee\u6539\u4ee3\u7801\u907f\u514d\u7167\u7247\u548c\u89c6\u9891\u6587\u4ef6\u88ab\u590d\u5236\u5230\u540c\u4e00\u4e2a\u6587\u4ef6\u5939\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u9700\u6c42\uff1a\u4fee\u6539json\u6587\u4ef6\u5e76\u590d\u5236\u6587\u4ef6\u5939\u5230\u65b0\u8def\u5f84<\/strong><\/p>\n<p><strong>1. \u73b0\u6709\u4ee3\u7801\u7684\u95ee\u9898<\/strong><\/p>\n<p>\u589e\u52a0\u590d\u5236\u5176\u4ed6\u6587\u4ef6\u4ee3\u7801\u540e\uff0c\u6240\u6709\u7167\u7247\u548c\u89c6\u9891\u6587\u4ef6\u88ab\u590d\u5236\u5230\u540c\u4e00\u4e2a\u6587\u4ef6\u5939\u4e2d\u3002<\/p>\n<p><strong>2. \u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u5728\u8fc7\u6ee4json\u6587\u4ef6\u7684get_json_data()\u51fd\u6570\u4e2d\uff0c\u8fc7\u6ee4\u6389\u4e0d\u9700\u8981\u590d\u5236\u7684\u6587\u4ef6\u7c7b\u578b\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>def get_json_data(old_json_path):\n    result = []\n    for root,dirs,files in os.walk(old_json_path):\n        for file_name in files:\n            if file_name.endswith('.json'):\n                old_json_file_path = os.path.join(root, file_name)\n                result.append(old_json_file_path)\n            elif file_name.endswith('.jpg') or file_name.endswith('.avi'):\n                # \u5c06\u7167\u7247\u548c\u89c6\u9891\u6587\u4ef6\u8def\u5f84\u52a0\u5165\u5217\u8868\n                result.append(os.path.join(root, file_name))\n    return result<\/pre>\n<p><strong>3. eof\u62a5\u9519\u7684\u539f\u56e0<\/strong><\/p>\n<p>\u95ee\u9898\u4e2d\u63d0\u5230\u7684json_date = f.read()\u548cjson_date_str = eval(json_date)\u9519\u8bef\u53ef\u80fd\u662f\u7531\u4e8ef.read()\u8bfb\u53d6\u5230\u7a7a\u5b57\u7b26\u4e32\u5bfc\u81f4\u7684\u3002<\/p>\n<pre>file_path = r'F:\\vscode_pj\\pj_test\\test_data\\1\\2.json'\n\nwith open(file_path) as f:\n    data = f.read()\n    # \u5224\u65addata\u662f\u5426\u4e3a\u7a7a\u5b57\u7b26\u4e32\n    if not data:\n        print(\"EOF error: Empty file.\")\n    else:\n        # \u5c06data\u8f6c\u6362\u4e3a\u5b57\u5178\n        b = eval(data)<\/pre>\n<p>\u4eca\u5929\u5173\u4e8e\u300a\u5982\u4f55\u4fee\u6539\u4ee3\u7801\u907f\u514d\u7167\u7247\u548c\u89c6\u9891\u6587\u4ef6\u88ab\u590d\u5236\u5230\u540c\u4e00\u4e2a\u6587\u4ef6\u5939\uff1f\u300b\u7684\u5185\u5bb9\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\uff0c\u5982\u679c\u6709\u4ec0\u4e48\u7591\u95ee\u6216\u8005\u5efa\u8bae\uff0c\u53ef\u4ee5\u5728\u7c73\u4e91\u516c\u4f17\u53f7\u4e0b\u591a\u591a\u56de\u590d\u4ea4\u6d41\uff1b\u6587\u4e2d\u82e5\u6709\u4e0d\u6b63\u4e4b\u5904\uff0c\u4e5f\u5e0c\u671b\u56de\u590d\u7559\u8a00\u4ee5\u544a\u77e5\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4fee\u6539\u4ee3\u7801\u907f\u514d\u7167\u7247\u548c\u89c6\u9891\u6587\u4ef6\u88ab\u590d\u5236\u5230\u540c\u4e00\u4e2a\u6587\u4ef6\u5939\uff1f \u77e5\u8bc6\u70b9\u638c\u63e1\u4e86\uff0c\u8fd8\u9700\u8981\u4e0d\u65ad\u7ec3\u4e60\u624d\u80fd\u719f\u7ec3\u8fd0\u7528\u3002\u4e0b\u9762\u7c73\u4e91\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u4e2a\u6587\u7ae0\u5f00\u53d1\u5b9e\u6218\uff0c\u624b\u628a\u624b\u6559\u5927\u5bb6\u5b66\u4e60\u300a\u5982\u4f55\u4fee\u6539\u4ee3\u7801\u907f\u514d\u7167\u7247\u548c\u89c6\u9891\u6587\u4ef6\u88ab\u590d\u5236\u5230\u540c\u4e00\u4e2a\u6587\u4ef6\u5939\uff1f\u300b\uff0c\u5728\u5b9e\u73b0\u529f\u80fd\u7684\u8fc7\u7a0b\u4e2d\u4e5f\u5e26\u5927\u5bb6\u91cd\u65b0\u6e29\u4e60\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6e29\u6545\u800c\u77e5\u65b0\uff0c\u56de\u5934\u770b\u770b\u8bf4\u4e0d\u5b9a\u53c8\u6709\u4e0d\u4e00\u6837\u7684\u611f\u609f\uff01 \u9700\u6c42\uff1a\u4fee\u6539json\u6587\u4ef6\u5e76\u590d\u5236\u6587\u4ef6\u5939\u5230\u65b0\u8def\u5f84 1. \u73b0\u6709\u4ee3\u7801\u7684\u95ee\u9898 \u589e\u52a0\u590d\u5236\u5176\u4ed6\u6587\u4ef6\u4ee3\u7801\u540e\uff0c\u6240\u6709\u7167\u7247\u548c\u89c6\u9891\u6587\u4ef6\u88ab\u590d\u5236\u5230\u540c\u4e00\u4e2a\u6587\u4ef6\u5939\u4e2d\u3002 2. \u89e3\u51b3\u65b9\u6848 \u5728\u8fc7\u6ee4json\u6587\u4ef6\u7684get_json_data()\u51fd\u6570\u4e2d\uff0c\u8fc7\u6ee4\u6389\u4e0d\u9700\u8981\u590d\u5236\u7684\u6587\u4ef6\u7c7b\u578b\uff0c\u4f8b\u5982\uff1a def get_json_data(old_json_path): result = [] for root,dirs,files in os.walk(old_json_path): for file_name in files: if file_name.endswith(&#8216;.json&#8217;): old_json_file_path = os.path.join(root, file_name) result.append(old_json_file_path) elif file_name.endswith(&#8216;.jpg&#8217;) or file_name.endswith(&#8216;.avi&#8217;): # \u5c06\u7167\u7247\u548c\u89c6\u9891\u6587\u4ef6\u8def\u5f84\u52a0\u5165\u5217\u8868 result.append(os.path.join(root, file_name)) return result 3. eof\u62a5\u9519\u7684\u539f\u56e0 \u95ee\u9898\u4e2d\u63d0\u5230\u7684json_date = f.read()\u548cjson_date_str = eval(json_date)\u9519\u8bef\u53ef\u80fd\u662f\u7531\u4e8ef.read()\u8bfb\u53d6\u5230\u7a7a\u5b57\u7b26\u4e32\u5bfc\u81f4\u7684\u3002 file_path = r&#8217;F:\\vscode_pj\\pj_test\\test_data\\1\\2.json&#8217; with open(file_path) as f: data = [&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-50005","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/50005","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=50005"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/50005\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=50005"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=50005"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=50005"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}