如何使用Python对JSON中的字典字段进行排序实例展示?
- 内容介绍
- 文章标签
- 相关推荐
本文共计368个文字,预计阅读时间需要2分钟。
以下是对给定代码的简化改写,不超过100个字:
pythondic={'a': 1, 'b': 2, 'c': 3}print(dic.items())jsons=json.dumps(dic)print(jsons)
结果:dict_items([('c', 3), ('b', 2), ('a', 1)]){c: 3, b: 2, a: 1}
如下所示:
dic = dict() dic['a'] = 1 dic['b'] = 2 dic['c'] = 3 print(dic.items()) import json jsons = json.dumps(dic) print(jsons)
结果:
dic is: dict_items([('c', 3), ('b', 2), ('a', 1)])
jsons: {"c": 3, "b": 2, "a": 1}
通过使用collecions,进行排序。collections是一个python的内建模块。
本文共计368个文字,预计阅读时间需要2分钟。
以下是对给定代码的简化改写,不超过100个字:
pythondic={'a': 1, 'b': 2, 'c': 3}print(dic.items())jsons=json.dumps(dic)print(jsons)
结果:dict_items([('c', 3), ('b', 2), ('a', 1)]){c: 3, b: 2, a: 1}
如下所示:
dic = dict() dic['a'] = 1 dic['b'] = 2 dic['c'] = 3 print(dic.items()) import json jsons = json.dumps(dic) print(jsons)
结果:
dic is: dict_items([('c', 3), ('b', 2), ('a', 1)])
jsons: {"c": 3, "b": 2, "a": 1}
通过使用collecions,进行排序。collections是一个python的内建模块。

