python中怎么对json数组按json的某个字段进行排序

如题所述

以下代码运行通过:

json_array = [{"time": 20150312, "value": "c"}, {"time": 20150301, "value": "a"}, {"time": 20150305, "value": "b"}]

json_array.sort(key=lambda x: x["time"])

print(json_array)

运行结果:

温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-12-07
dict1 = {'a':2,'c':3,'b':4}
# 按照key进行排序 
print sorted(dict1.items(), key=lambda d: d[0]) 
# 按照value进行排序 
print sorted(dict1.items(), key=lambda d: d[1])

本回答被提问者采纳
相似回答