【发布时间】:2019-06-09 01:38:16
【问题描述】:
我正在尝试使用 Python 解析以下学生成绩报告 JSON
{
"report":[
{
"enrollment": "rit2011001",
"name": "Julia",
"subject":[
{
"code": "DSA",
"grade": "A"
}
]
},
{
"enrollment": "rit2011020",
"name": "Samantha",
"subject":[
{
"code": "COM",
"grade": "B"
},
{
"code": "DSA",
"grade": "A"
}
]
}
]
}
这样报告应首先按代码升序排列,然后按年级升序排列,然后按入学率升序排列。输出应该是这样的
COM B rit2011020 Samantha
DSA A rit2011001 Julia
DSA A rit2011020 Samantha
这是我需要帮助的不完整代码:
import json
data='''{
"report":[
{
"enrollment": "rit2011001",
"name": "Julia",
"subject":[
{
"code": "DSA",
"grade": "A"
}
]
},
{
"enrollment": "rit2011020",
"name": "Samantha",
"subject":[
{
"code": "COM",
"grade": "B"
},
{
"code": "DSA",
"grade": "A"
}
]
}
]
}'''
print data #for debug
parsed_json = json.loads(data)
print parsed_json #for debug
for key,value in sorted(parsed_json.items()):
print key,value
我不知道如何应用连续过滤来达到结果。
【问题讨论】:
-
@jmoney 我已经查看了示例并尝试按照它进行操作,但出现错误
标签: python json sorting dictionary python-2.x