把 Python 对象转换为 JSON 字符串

  1. import json
  2.  
  3. print(json.dumps({"name": "Bill", "age": 63}))
  4. print(json.dumps(["apple", "bananas"]))
  5. print(json.dumps(("apple", "bananas")))
  6. print(json.dumps("hello"))
  7. print(json.dumps(42))
  8. print(json.dumps(31.76))
  9. print(json.dumps(True))
  10. print(json.dumps(False))
  11. print(json.dumps(None))