从我的React应用程序中,我通过DjangoAPI的后端获得以下Json
{'0': {'title': 'The Title?', 'text': 'rdhdrhdr'}, '1': {'title': 'The Title2', 'text': 'hdrhdhdrh'}}
然后我尝试通过for循环迭代一些数据
def post(self, request):
data = request.data
print(data)
for a in data:
print(a['title'])
如果我希望它打印标题和标题2,我会得到以下错误
print(a['title'])
TypeError: string indices must be integers
我认为我的json有问题。。但是我想不出来
您正在迭代字典的键,而不是数据。您要做的是:
相关问题 更多 >
编程相关推荐