Python的哪些类型可以转为JSON字符串?

1 个回答|56 次阅读
Coco老师 - 科普专家
擅长:编程教育

字典、列表、元组、字符串、整型、浮点型、真、假、None

import json
print(json.dumps({"name": "小花", "age": 90}))
print(json.dumps(["apple", "bananas"]))
print(json.dumps(("apple", "bananas")))
print(json.dumps("hello"))
print(json.dumps(89))
print(json.dumps(69.76))
print(json.dumps(True))
print(json.dumps(False))
print(json.dumps(None))

执行结果:

{"name": "\u5c0f\u82b1", "age": 90}
["apple", "bananas"]
["apple", "bananas"]
"hello"
89
69.76
true
false
null