Convert a python dict to a string and back

后端 未结 10 1656
清酒与你
清酒与你 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条回答
  •  旧时难觅i
    2020-11-27 10:58

    If you care about the speed use ujson (UltraJSON), which has the same API as json:

    import ujson
    ujson.dumps([{"key": "value"}, 81, True])
    # '[{"key":"value"},81,true]'
    ujson.loads("""[{"key": "value"}, 81, true]""")
    # [{u'key': u'value'}, 81, True]
    

提交回复
热议问题