租用问题

质量为本、客户为根、勇于拼搏、务实创新

< 返回租用问题列表

python中print()怎样优雅地打印JSON,python中print怎么输出两个值

发布时间:2024-07-14 15:40:24

python中print()怎样优雅地打印JSON

在Python中,可使用json.dumps()方法来将JSON对象转换为字符串,然后使用print()方法打印出来。这样可以更加优雅地打印JSON数据。

例如:

import json

data = {'name': 'John', 'age': 30, 'city': 'New York'}
json_str = json.dumps(data, indent=4)

print(json_str)

这样就会以缩进的情势打印出JSON数据,使其更加易于浏览。

tiktok粉丝购买:https://www.smmfensi.com/