Python 代码:
当我执行:
import json
aaa='''
{
"eee":"yes",
"something": null,
"ok": ["no","mmm","eee"],
"please":false,
"no": {"f":true,"h":"ttt"}
}
'''
data=json.loads(aaa)
当我执行:
print(len(data))
我得到了预期的结果:
5
并且
print(len(data['ok']))
这提供了
3
但不知何故
print(data[0])
提供
Traceback (most recent call last):
File "file.py", line 34, in <module>
print(data[0])
KeyError: 0
如何使用其索引获取JSON对象中的项?
0
的项。 - floss