字典按Key排序 转字符串

字典按Key排序 转字符串

janice No Comment
Python 学习笔记

普通字典默认是无序的,有序的字典需要用到OrderedDict:

简单例子如下:

import collections,json

json_send = {"Timeout": "10", "CNCFile": "O6666", "CNC": "CNC_3", 
"LocalFile": "E:\\xtec\\test\\TESTING",
"CNCPath": "//CNC_MEM/USER/PATH1/", "Command": "FTPSendFile"}

d1 = collections.OrderedDict()
for i in sorted(json_send): 
    d1[i] = json_send[i]
    print(d1)
print(json.dumps(d1))

发表评论

分类目录

关于我

 Janice 詹

QQ   455899417

janice2014@foxmail.com