We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
其中的mode表示是否换行保存text内容。
import json json_file = r"G:\Desktop\python小项目\调用微信ocr进行识别文字\2.png.json" save_file = "save.txt" def save_text(json_file, save_file, mode=1): # 打开 JSON 文件 with open(json_file, 'r', encoding='utf-8') as file: # 从文件中加载 JSON 数据 data = json.load(file) # 换行保存 if mode == 1: with open(save_file, 'w', encoding='utf-8') as f: # 提取每个对象的 text 字段 for item in data['ocrResult']: print(item['text']) f.write(item['text'] + '\n') # 不换行保存 if mode == 2: with open(save_file, 'w', encoding='utf-8') as f: # 提取每个对象的 text 字段 for item in data['ocrResult']: print(item['text']) f.write(item['text']) save_text(json_file, save_file, mode=1)
The text was updated successfully, but these errors were encountered:
这项目不是新手教程,新手想学习应该去看Python教程
Sorry, something went wrong.
No branches or pull requests
其中的mode表示是否换行保存text内容。
The text was updated successfully, but these errors were encountered: