DictionaryByGPT4 icon indicating copy to clipboard operation
DictionaryByGPT4 copied to clipboard

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

Open WangYQ999 opened this issue 1 year ago • 2 comments

WangYQ999 avatar Jul 04 '24 07:07 WangYQ999

同问

jianglin-code avatar Jul 06 '24 11:07 jianglin-code

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

LjyLab avatar Jul 06 '24 18:07 LjyLab