如何在python中获取数组json的键和值
我有一个示例数组json:如何在python中获取数组json的键和值,python,arrays,json,Python,Arrays,Json,我有一个示例数组json: [ { 'Clothes':[ { 'id': '32705111', 'describes': 'no problem' } ] }, { 'Dress':[ { 'id': '32705111',
[
{
'Clothes':[
{
'id': '32705111',
'describes': 'no problem'
}
]
},
{
'Dress':[
{
'id': '32705111',
'describes': 'no outfit'
}
]
}
]
预期:我希望通过PyThon获得每个数组的名称和所有数组元素,例如'Cloth'和'Dress'是一个数组的名称
Clothes[{'id': '32705111','describes': 'no problem'}], Dress[{'id': '32705111', 'describes': 'no outfit'}]
请帮我解决这个问题。非常感谢你,我爱你 试试下面的代码,我想这就是你要找的
json_arr = [
{
'Clothes': [
{
'id': '32705111',
'describes': 'no problem'
}
]
},
{
'Dress': [
{
'id': '32705111',
'describes': 'no outfit'
}
]
}
]
for d in json_arr:
for name, array in d.items():
globals()[name] = array
new_lst = []
for i in json_array:
for name, array in i.items():
value = ''.join(str(array))
result = name+value
new_lst.append(result)
print(new_lst)
输出-
["Clothes[{'id': '32705111', 'describes': 'no problem'}]", "Dress[{'id': '32705111', 'describes': 'no outfit'}]"]
问问题时最好表现出你对问题的尝试。你能把你当前的代码和你的问题一起发布吗?非常感谢,这个问题花了我很多时间,你帮了我。再次感谢您非常感谢这段代码,但这对我的问题没有好处。