json.loads更改传递的字符串中给出的键的顺序

时间:2014-08-30 04:30:16

标签: python json django

 >>> x='{"Title":"test","Description":"test des","Colo":"test colo1","Expected Date":"1234","Comboboxes":"option1","Checkboxes":["option1","option2"]}'
 >>> x
'{"Title":"test","Description":"test des","Colo":"test colo1","Expected Date":"1234","Comboboxes":"option1","Checkboxes":["option1","option2"]}'
 >>> json.loads(x)
{'Expected Date': '1234', 'Description': 'test des', 'Title': 'test', 'Comboboxes': 'option1', 'Colo': 'test colo1', 'Checkboxes': ['option1', 'option2']}

请帮我按照给定字符串的顺序获取这些键。

1 个答案:

答案 0 :(得分:1)

json.loads()生成一个Python字典,从内部散列表中获取它的排序。您可以使用sorted()对它们进行排序,但不能订购标准词典。如果需要,您可以使用OrderedDict