我只是想按顺序保持以下输入和生成的 JSON 字符串。
这是输入字符串和代码:
import json
testlist=[]
# we create a list as a tuple so the dictionary order stays correct
testlist=[({"header":{"stream":2,"function":3,"reply":True},"body": [({"format": "A", "value":"This is some text"})]})]
print 'py data string: '
print testlist
data_string = json.dumps(testlist)
print 'json string: '
print data_string
这是输出字符串:
json string:
[{"body": [{"format": "A", "value": "This is some text"}], "header": {"stream": 2, "function": 3, "reply": true}}]
我试图保持输出的顺序与输入的顺序相同。
任何帮助都会很棒。我似乎无法弄清楚这一点。