我在以下代码中得到错误“TypeError:字符串索引必须是整数”:
if body['category'] == 'Character':
return sanic.response.json([], status=200)
正文:
{
"lockerItem": "sandbox_loadout",
"category": "Character",
"itemToSlot": "AthenaCharacter:CID_279_Athena_Commando_M_TacticalSanta",
"slotIndex": 0,
"variantUpdates": [
{
"channel": "Parts",
"active": "Stage0",
"owned": []
}
],
"optLockerUseCountOverride": -1
}
完全错误:
if body['category'] == 'Character':
TypeError: string indices must be integers
验证
body
变量类型,之所以得到TypeError: string indices must be integers
是因为body
是字符串类型,并且只能对字符串使用整数索引您需要将变量转换为可以使用字符串索引的dict类型,或者确保收到的变量为dict类型
相关问题 更多 >
编程相关推荐