传出事件表示“from”的值=4 有人能帮我写代码吗。我卡住了
eg:
({'date': '20090328',
'time': '061546',
'from': '4',
'to': '12',
'cell_tower': '220',
'event_type': 'MOC'},
{'date': '20090328',
'time': '053359',
'from': '4',
'to': '2',
'cell_tower': '221',
'event_type': 'SOM'},
)
json文件:
{'user': '4', 'data': [{'date': '20090328', 'time': '061546', 'from': '4', 'to': '12', 'cell_tower': '220', 'event_type': 'MOC'}, {'date': '20090328', 'time': '053359', 'from': '4', 'to': '2', 'cell_tower': '221', 'event_type': 'SOM'}, {'date': '20090328', 'time': '012339', 'from': '6', 'to': '4', 'cell_tower': '14054', 'event_type': 'MOC'}
见下文(一个班轮)
输出
使用名为
filename.json
的json文件:python代码如下所示:
问题是您的输入数据不是有效的
json
格式,因为json
需要在其值周围加上双引号您需要首先读取数据并用
"
替换所有'
,然后使用json格式化为json
对象,然后使用列表理解来获得结果输出:
相关问题 更多 >
编程相关推荐