【发布时间】:2016-10-08 22:23:50
【问题描述】:
我的任务是将来自两个不同来源的数据组合成一个 JSON 以供 Web 服务使用。我决定使用我发现非常容易使用的烧瓶。 无论如何,我正在检索看起来像这样的 JSON(通过 urlib2)....
[
[{
"timestamp": 1474088400000,
"errors": 1018831,
"errorTotal": 72400021,
"errorTotal2": 0.013022892930509898,
"business": 4814994,
"breakdown": [{
"type": "type1",
"count": 603437
}, {
"type": "type2",
"count": 256187
}]
}]
]
我要做的就是在“breakdown”下添加一个新的密钥对,特别是“type3”,所以 JSON 对象看起来像这样......
[
[{
"timestamp": 1474088400000,
"errors": 1018831,
"errorTotal": 72400021,
"errorTotal2": 0.013022892930509898,
"business": 4814994,
"breakdown": [{
"type": "type1",
"count": 603437
}, {
"type": "type2",
"count": 256187
}, {
"type": "type3",
"count": 4533
}]
}]
]
我认为将其视为列表中的密钥对是可行的方法,但它似乎不起作用。谁能指出我正确的方向? 非常感谢!
【问题讨论】:
-
看起来那是一个列表,可以在 python 中使用
d[0][0]['breakdown'].append({"type": "type3", "count": 4533})附加到它
标签: python json python-2.7