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/
TOP