List of objects to JSON with Python

前端 未结 3 849
鱼传尺愫
鱼传尺愫 2020-12-05 02:24

I have a problem converting Object instances to JSON:

ob = Object()

list_name = scaping_myObj(base_url, u, number_page)

for ob in list_name:
          


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-05 03:15

    Similar to @MartijnPieters' answer, you can use the json.dumps default parameter with a lambda, if you don't want to have to create a separate function: json.dumps(obj, default = lambda x: x.__dict__)

提交回复
热议问题