【发布时间】:2018-04-22 16:25:15
【问题描述】:
counter={"a":1,"b":2}
With open('egg.json' , 'w') as json_file:
json.dump(counter, json_file)
所以当我查看我的 json 文件时,它会显示: {a:1 , b:2} 但我需要它是这样的:
[[a:1],[b:2]]
我已经尝试添加
json.dump(counter, json_file, separator (' [ ', ' ] ')
但是没有什么能解决问题... 有没有办法像格式化 CSV 文件一样格式化 json 文件? 我真的很想知道.....谢谢。
【问题讨论】:
-
您为什么要这样做? dict 格式为 {} ...你知道xy-Problems
-
如果你生成了无效的 json,你就会给消费者带来很大的困难——想想看。
标签: json python-3.x formatting