Python语言基础
Python语言进阶
Python数据结构

Python 对象转换为 JSON

Python 对象转换为 JSON详细操作教程
以下实例为学习把 Python 对象转换为 JSON 字符串,具体代码如下:
# Filename : example.py
# Author by : www.lidihuo.com
import json
print(json.dumps({"name": "Bill", "age": 63}))
print(json.dumps(["apple", "bananas"]))
print(json.dumps(("apple", "bananas")))
print(json.dumps("hello"))
print(json.dumps(42))
print(json.dumps(31.76))
print(json.dumps(True))
print(json.dumps(False))
print(json.dumps(None))
执行以上代码输出结果为:
# Filename : example.py
# Author by : www.lidihuo.com

{"name""Bill""age": 63}

["apple""bananas"]

["apple", "bananas"]

"hello"

42

31.76

true

False

null

昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4