关于如何自定义OrderedDict
格式并将其转换为json或dictionary格式(但是能够重置键名和结构),我遇到了一个问题。我有以下数据:
result= OrderedDict([('index', 'cfs_fsd_00001'),
('host', 'GIISSP707'),
('source', 'D:\\usrLLSS_SS'),
('_time', '2018-11-02 14:43:30.000 EDT'),
('count', '153')])
…但是,我想更改如下格式:
{
"servarname": {
"index": "cfs_fsd_00001",
"host": "GIISSP707"
},
"times": '2018-11-02 14:43:30.000 EDT',
"metricTags": {
"source": 'D:\\ddevel.log'"
},
"metricName": "serverice count",
"metricValue": 153,
"metricType": "count"
}
我将非常感谢你的帮助。基本上我得到的输出是相当平坦的。但我想定制结构。原来的结构是
OrderedDict([('index','cfs\u fsd\u 00001'),('host','GIISSP707')…])。你知道吗
我要实现的输出是{“servarname”{“index”:“cfs\u fsd\u 00001”,“host”:“GIISSP707”},。。。。。。你知道吗
您可以简单地引用
result
dict和您希望目标数据结构具有的相应键:不知道你的方法需要多灵活。我假设您在OrderedDict中有一些公共键,您希望在那里找到度量,然后将它们重新格式化为新的dict。你知道吗
相关问题 更多 >
编程相关推荐