Recursively convert python object graph to dictionary

前端 未结 9 1603
既然无缘
既然无缘 2020-12-04 10:25

I\'m trying to convert the data from a simple object graph into a dictionary. I don\'t need type information or methods and I don\'t need to be able to convert it back to an

9条回答
  •  南方客
    南方客 (楼主)
    2020-12-04 10:44

    A slow but easy way to do this is to use jsonpickle to convert the object to a JSON string and then json.loads to convert it back to a python dictionary:

    dict = json.loads(jsonpickle.encode( obj, unpicklable=False ))

提交回复
热议问题