Ceelog / DictionaryByGPT4

一本 GPT4 生成的单词书📚,超过 8000 个单词分析,涵盖了词义、例句、词根词缀、变形、文化背景、记忆技巧和小故事
https://ceelog.github.io/DictionaryByGPT4/
Creative Commons Attribution Share Alike 4.0 International
3.17k stars 208 forks source link

大佬有代码吗,我想二次开发 #13

Open WangYQ999 opened 2 months ago

jianglin-code commented 2 months ago

同问

LjyLab commented 2 months ago
import json
def process_json_lines(input_file, output_file):
    fixed_data = []
    with open(input_file, 'r', encoding='utf-8') as infile:
        for line in infile:
            try:
                # 解析每一行JSON数据
                json_data = json.loads(line.strip())
                # 这里可以根据需要对json_data进行处理
                fixed_data.append(json_data)
            except json.JSONDecodeError as e:
                print(f"Error decoding JSON: {e} in line: {line}")

    # 将所有解析和处理后的数据写入输出文件,格式化为JSON数组
    with open(output_file, 'w', encoding='utf-8') as outfile:
        json.dump(fixed_data, outfile, ensure_ascii=False, indent=4)

input_file = 'gptwords.json'
output_file = 'gptwords.out.json'
process_json_lines(input_file, output_file)

JSON: gptwords.out.json SQL: words.txt