根据您对输出所做的操作,一种选择是将JSON用于显示。
import jsonx = {'planet' : {'has': {'plants': 'yes', 'animals': 'yes', 'cryptonite': 'no'}, 'name': 'Earth'}}print json.dumps(x, indent=2)输出:
{ "planet": { "has": { "plants": "yes", "animals": "yes", "cryptonite": "no" }, "name": "Earth" }}需要注意的是,这种方法无法通过JSON序列化。如果字典包含不可序列化的项(例如类或函数),则需要一些额外的代码。



