【发布时间】:2010-11-05 14:36:21
【问题描述】:
呼应我的other question 现在需要找到一种方法将 json 压缩到一行:例如
{"node0":{
"node1":{
"attr0":"foo",
"attr1":"foo bar",
"attr2":"value with long spaces"
}
}}
想压缩成一行:
{"node0":{"node1":{"attr0":"foo","attr1":"foo bar","attr2":"value with long spaces"}}}
通过删除无关紧要的空格并保留值内的空格。在 python 中是否有一个库可以做到这一点?
编辑 感谢 drdaeman 和 Eli Courtwright 的快速响应!
【问题讨论】:
-
您使用的 Python 版本在这里有些相关。自(我认为)2.6 以来,json 一直是标准库的一部分
-
使用 python 2.6,所以建议的解决方案对我很有效