我有json数据与关系,但我不能循环它
{
"data": {
"id": 2,
"name": "My TEST",
"image": "1.jpg",
"article": [
{
"id": 1,
"name": "TEST"
}
]
}
}
我试着像
myitems = []
for item in json_data['data']:
myitems.append({
'title': item['name'],
'image': item['image'],
'article_id': item['article'][0]['id']
})
它告诉我
TypeError: string indices must be integers
编辑
正如blender所说,您正在浏览字典键。这将起作用:
改变
至
不过,正如blender提到的,您不需要迭代。你知道吗
我知道了。循环在一篇文章上。你知道吗
相关问题 更多 >
编程相关推荐