作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我使用这段代码将 dict
漂亮地打印成 JSON:
import json
d = {'a': 'blah', 'b': 'foo', 'c': [1,2,3]}
print json.dumps(d, indent = 2, separators=(',', ': '))
输出:
{
"a": "blah",
"c": [
1,
2,
3
],
"b": "foo"
}
这有点太多(每个列表元素换行!)。
我应该使用哪种语法来实现:
{
"a": "blah",
"c": [1, 2, 3],
"b": "foo"
}
代替?
最佳答案
我最终使用了 jsbeautifier :
import jsbeautifier
opts = jsbeautifier.default_options()
opts.indent_size = 2
jsbeautifier.beautify(json.dumps(d), opts)
输出:
{
"a": "blah",
"c": [1, 2, 3],
"b": "foo"
}
关于python - pretty-print JSON 转储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21866774/
我正在为我的应用程序使用 Tank-Auth。我唯一的问题是激活和重置帐户密码。 用于登录、注册、注销;我对这些代码没有问题; $route['login'] = "/auth/login"; $ro
我是一名优秀的程序员,十分优秀!