Python在解析request.data时给出TypeError

2024-09-23 10:34:26 发布

您现在位置:Python中文网/ 问答频道 /正文

从我的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有问题。。但是我想不出来


Tags: thetextjson应用程序标题fordatatitle