[ { "branch_id": 5, "branch_name": "分院2", "major_id": 3, "major_name": "专业2", "class_id": 5, "class_name": "班级2", "student_id": 11, "name": "xs1" }, { "branch_id": 5, "branch_name": "分院2", "major_id": 3, "major_name": "专业2", "class_id": 5, "class_name": "班级2", "student_id": 10, "name": "xs3" }, { "branch_id": 5, "branch_name": "分院2", "major_id": 3, "major_name": "专业2", "class_id": 5, "class_name": "班级2", "student_id": 9, "name": "bj2xs3" }, { "branch_id": 5, "branch_name": "分院2", "major_id": 3, "major_name": "专业2", "class_id": 5, "class_name": "班级2", "student_id": 8, "name": "bj2xs2" } ]
时间: 2023-07-02 14:13:00 浏览: 67
git_branch_practice:使用git分支练习的示例仓库
这是一个 JSON 格式的数据,它表示了一个班级的学生信息列表。如果你需要对这些数据进行处理,例如按照学生编号升序排序,可以使用以下 Python 代码:
```python
import json
data = [
{
"branch_id": 5,
"branch_name": "分院2",
"major_id": 3,
"major_name": "专业2",
"class_id": 5,
"class_name": "班级2",
"student_id": 11,
"name": "xs1"
},
{
"branch_id": 5,
"branch_name": "分院2",
"major_id": 3,
"major_name": "专业2",
"class_id": 5,
"class_name": "班级2",
"student_id": 10,
"name": "xs3"
},
{
"branch_id": 5,
"branch_name": "分院2",
"major_id": 3,
"major_name": "专业2",
"class_id": 5,
"class_name": "班级2",
"student_id": 9,
"name": "bj2xs3"
},
{
"branch_id": 5,
"branch_name": "分院2",
"major_id": 3,
"major_name": "专业2",
"class_id": 5,
"class_name": "班级2",
"student_id": 8,
"name": "bj2xs2"
}
]
sorted_data = sorted(data, key=lambda x: x['student_id'])
print(json.dumps(sorted_data, indent=4, ensure_ascii=False))
```
运行结果如下:
```
[
{
"branch_id": 5,
"branch_name": "分院2",
"major_id": 3,
"major_name": "专业2",
"class_id": 5,
"class_name": "班级2",
"student_id": 8,
"name": "bj2xs2"
},
{
"branch_id": 5,
"branch_name": "分院2",
"major_id": 3,
"major_name": "专业2",
"class_id": 5,
"class_name": "班级2",
"student_id": 9,
"name": "bj2xs3"
},
{
"branch_id": 5,
"branch_name": "分院2",
"major_id": 3,
"major_name": "专业2",
"class_id": 5,
"class_name": "班级2",
"student_id": 10,
"name": "xs3"
},
{
"branch_id": 5,
"branch_name": "分院2",
"major_id": 3,
"major_name": "专业2",
"class_id": 5,
"class_name": "班级2",
"student_id": 11,
"name": "xs1"
}
]
```
以上代码使用了 Python 的 `sorted` 函数和 lambda 表达式对列表进行排序,然后使用 `json.dumps` 函数将结果转换为 JSON 格式的字符串并输出。
阅读全文