[英]TypeError: string indices must be integers with .json() dictionary
[英]TypeError: string indices must be integers in json
我有一本包含这样一个列表的字典
data = {'data': [18,170,457,99,40,0,0,4,
434,168,454,99,40,3,1,
0, 421,168,452,100,41,2,
0,4,455,13,32,11,6,
0,0,4,279,14,46,10,5,
0,0,1,257,13,44,10,5,
1,1,254,0]}
当我尝试将其转换为 json 时,它给了我一个错误
json.dumps(data)['data']
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-94-ca909e16d3cc> in <module>
6 0,0,1,257,13,44,10,5,
7 1,1,254,0]}
----> 8 json.dumps(data)['data']
TypeError: string indices must be integers
如果要将 JSON 字符串转换回必须使用的字典,则将字典转换为字符串json.loads(json_string)
JSON 对象几乎在每种语言中都是实际 Javascript 对象的字符串表示形式 您可以将其用作Python 中的一个 dict 但如果你想让它导出它你需要把它串起来
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.