Convert a python dict to a string and back

后端 未结 10 1650
清酒与你
清酒与你 2020-11-27 10:17

I am writing a program that stores data in a dictionary object, but this data needs to be saved at some point during the program execution and loaded back into the dictionar

10条回答
  •  星月不相逢
    2020-11-27 10:58

    If in Chinses

    import codecs
    fout = codecs.open("xxx.json", "w", "utf-8")
    dict_to_json = json.dumps({'text':"中文"},ensure_ascii=False,indent=2)
    fout.write(dict_to_json + '\n')
    

提交回复
热议问题