我有Json文件包含以下行:
{
"tenant_EntityID": {
"s": "12345"
},
"enrtyDate": {
"s": "7.9.2000 14:53:45"
},
"first_name": {
"s": "Y7M9"
},
"last_name": {
"s": "NUYE"
},
"gender": {
"s": "male"
},
"birth_incorp_date": {
"s": "9.3.1999 14:49:44"
},
"email": {
"s": "0XPY9E@C20R.com"
}
}
当我试图通过以下代码将其加载到DynamoDB时:
^{pr2}$我得到了一个错误:
Traceback (most recent call last):
File "C:/Freedom/Comparing json file.py", line 39, in <module>
'tenant_EntityID':Entity['tenant_EntityID'] ,
TypeError: string indices must be integers
当您将JSON字符串读入实体时,结果是一个dict,带有键
"tenant_EntityID"
等等。语句for Entity in Entities
在该dict上迭代,给出dict的键,即字符串。在看起来你需要这样的东西:
我猜想您需要与
's'
键关联的值。在你说“当你用2行运行”时它失败了,很可能JSON应该被转换成一个字典列表,而不是一个字典。在
相关问题 更多 >
编程相关推荐