在 Python 的 STL 中使用 json 并想出了这个..
import json as j
cred = j.dumps({'Name': 'John Doe', 'Occupation': 'Programmer'},
sort_keys = True,
indent = 4,
separators = (',', ': '))
_f = open('credentials', 'w')
_f.write(cred)
_f.close()
输出如下,一切都很好..
{
"Name": "John Doe", "Occupation": "Programmer"
}
但是,我不小心这样输入了小写的名称..
cred = j.dumps({'name': 'John Doe', 'Occupation': 'Programmer'},
sort_keys = True,
indent = 4,
separators = (',', ': '))
结果是这样的..
{
"Occupation": "Programmer", "name": "John Doe"
}
json如何确定传递给它的值的写入/输出顺序,大写字母优先于小写字母,反之亦然,有没有办法保持顺序?