Skip to content
New issue

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

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

Open
WangYQ999 opened this issue Jul 4, 2024 · 2 comments
Open

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

WangYQ999 opened this issue Jul 4, 2024 · 2 comments

Comments

@WangYQ999
Copy link

No description provided.

@jianglin-code
Copy link

同问

@LjyLab
Copy link

LjyLab commented Jul 6, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants