1 回答
TA贡献1772条经验 获得超8个赞
使用json模块将字符串加载到列表中。遍历列表中的字典并设置一个属性 -calc为lat值减去50。
最后,如果需要,将列表转储到带有可选indentarg的字符串中,以进行漂亮的打印。
import json
s = '''[{
"lat": 43.96063343238712,
"panoid": "sffcNG69c2kdZwEuYp1htw",
"lon": 3.098330084924494
}, {
"lat": 43.96052745649745,
"panoid": "2rJPv_r0gC5FBPLZK5vHDA",
"lon": 3.098487422195691
}]'''
l = json.loads(s)
for d in l:
d['calc'] = d['lat'] - 50
print(json.dumps(l, indent=4))
给予:
[
{
"lat": 43.96063343238712,
"panoid": "sffcNG69c2kdZwEuYp1htw",
"lon": 3.098330084924494,
"calc": -6.0393665676128805
},
{
"lat": 43.96052745649745,
"panoid": "2rJPv_r0gC5FBPLZK5vHDA",
"lon": 3.098487422195691,
"calc": -6.039472543502548
}
]
添加回答
举报