转换包含所有合法数据类型的 Python 对象

  1. import json
  2.  
  3. x = {
  4. "name": "Bill",
  5. "age": 63,
  6. "married": True,
  7. "divorced": False,
  8. "children": ("Jennifer","Rory","Phoebe"),
  9. "pets": None,
  10. "cars": [
  11. {"model": "Porsche", "mpg": 38.2},
  12. {"model": "BMW M5", "mpg": 26.9}
  13. ]
  14. }
  15.  
  16. print(json.dumps(x))