我有一个这样的 JSON 文件:
[
{
"course": "CMPT 102 D1",
"instructor": "hamarneh",
"students": [
"axc5",
"csf10",
"ctu1",
"nmw15",
"nsm12",
"ppy1",
"qtg13",
"tim1",
"tkd10",
"vhm8",
"vsv1",
"wps1",
"xup12",
"yqt6"
],
"title": "Scientific Cmpt.Prgm"
}]
这是我在python中的代码:
import json
json_data=open('jsonfile')
data=json.load(json_data)
print(data['students'])
但它显示一个错误:
print(data['students'])
TypeError: list indices must be integers, not str
请帮忙!
还有一个问题:假设 JSON 文件包含许多具有上述结构的课程。我该怎么做:
Select students, count(course) as course_number from tblstudent
group by students