1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| import json
""" 使用VLOOKUP在新增列中反映枚举的值 =VLOOKUP(A1,Sheet2!A:B,2,FALSE) """
def text_to_enum_json(input_file, output_file): enum_list = [] value_counter = 1 with open(input_file, 'r', encoding='utf-8') as f: lines = f.readlines() for line in lines: # 去除换行符并构建字典添加到列表 clean_line = line.strip() enum_list.append({"value": str(value_counter), "label": clean_line}) value_counter += 1
json_data = { "uiSchema": { "enum": enum_list, "type": "string", "x-component": "Select", "title": "字段名" } }
with open(output_file, 'w', encoding='utf-8') as f: json.dump(json_data, f, indent=None, ensure_ascii=False)
if __name__ == "__main__": input_file = "t.txt" output_file = "e.json" text_to_enum_json(input_file, output_file)
|