python 字典转json
def submit(path): data = [] for line in open(path): if not line.strip(): continue _ = json.loads(line.strip()) res = predict(_["text"]) data.append(json.dumps({"id":_['id'],"text":_["text"],"label": res}, ensure_ascii=False)) open("ner_predict.json", "w").write("\n".join(data))