import json # 读取 CSV,去掉空白列 df = pd.read_csv(file_path, usecols=["题干(必填)", "正确答案\n(必填)"]) # 定义映射:判断题“正确”/“错误” -> A / B ans_map = {"正确": "A", "错误": "B"} # 构造结果列表 result = [] for _, row in df.iterrows(): q = str(row["题干(必填)"]).strip() ans_text = str(row["正确答案\n(必填)"]).strip() ans = ans_map.get(ans_text, ans_text) # 如果不是判断题格式,就原样保留 a = ["A.正确", "B.错误"] result.append({"q": q, "a": a, "ans": ans}) # 保存为一行一个 JSON output_path = "/mnt/data/questions.json" with open(output_path, "w", encoding="utf-8") as f: for item in result: f.write(json.dumps(item, ensure_ascii=False) + "\n")