【发布时间】:2021-06-04 11:56:15
【问题描述】:
我使用以下代码:
import json
full_json = "{'Nike - Hombres Tenis Fila': ['/nike/casual/', '100', '/medias/']}"
jtopy=json.dumps(full_json) #json.dumps take a dictionary as input and returns a string as output.
dict_json=json.loads(jtopy)
print(dict_json['Nike - Hombres Tenis Fila'][0])
如何获得价值: /nike/casual/runners/'
我不断收到错误:
TypeError:字符串索引必须是整数
【问题讨论】:
-
"json.dumps 将字典作为输入 [...]" 但
full_json是字符串,而不是字典 -
而
full_json甚至不是一个有效的 json 字符串...您尝试在非 json 输入上使用 json 模块。
标签: python json python-3.x jsonparser