解析数组中的json嵌套字典

时间:2017-04-20 11:35:40

标签: json python-3.x

如何转换

json_decode = [{"538":["1,2,3","hello world"]},{"361":["0,9,8","x,x,y"]}]

{"538":["1,2,3","hello world"],"361":["0,9,8","x,x,y"]}

在python中?

2 个答案:

答案 0 :(得分:0)

我猜你用的是:

def merge_dicts(dict1, dict2):
    return dict(list(dict1.items()) + list(dict2.items()))

l = [{"538":["1,2,3","hello world"]},{"361":["0,9,8","x,x,y"]}]   
print merge_dicts(l[0], l[1])

输出:

{'361': ['0,9,8', 'x,x,y'], '538': ['1,2,3', 'hello world']}

答案 1 :(得分:0)

如果保证json_decode是list的{​​{1}},您可以使用以下内容获得所需的输出:

dictionaries

我希望这会有所帮助。

相关问题