【发布时间】:2021-12-11 21:31:22
【问题描述】:
我想从这个 json 响应中提取数据作为分组(结果、情感、心理运动和其他)从 api 中提取,但我对如何处理它感到困惑。 如果没有分组我可以完美处理,但分组时我迷路了。
{
"result": [{
"subject": "AGRICULTURE SCIENCE",
"ca1": "21",
"ex1": "60",
"t1total": 81,
"ca2": "21",
"ex2": "53",
"t2total": 74,
"ca3": "28",
"ex3": "60",
"t3total": 88,
"overalltotal": 243,
"avr": 81
}, {
"subject": "BASIC SCIENCE",
"ca1": "27",
"ex1": "49",
"t1total": 76,
"ca2": "22",
"ex2": "29",
"t2total": 51,
"ca3": "17",
"ex3": "41",
"t3total": 58,
"overalltotal": 185,
"avr": 61.67
}, {
"subject": "BASIC TECHNOLOGY",
"ca1": "30",
"ex1": "66",
"t1total": 96,
"ca2": "27",
"ex2": "62",
"t2total": 89,
"ca3": "22",
"ex3": "26",
"t3total": 48,
"overalltotal": 233,
"avr": 77.67
},],
"others": {
"pricomment": "He is a good boy",
"tcomment": "He is a gentle boy",
"term1total": 1308,
"term2total": 1315,
"term3total": 1212,
"overalltotal": 3835,
"overallavr": 75.19607843137254,
"test1total": "404",
"test12total": "406",
"test13total": "400",
"exam1total": "904",
"exam2total": "909",
"exam3total": "812"
},
"affective": {
"col1": "-",
"col2": "-",
"col3": "-",
"col4": "-",
"col5": "-",
"col6": "-",
"col7": "-",
"col8": "-"
},
"psychomotor": {
"col1": "-",
"col2": "-",
"col3": "-",
"col4": "-"
}
}
我试过这样做
void getTerm1Result() async {
final response = await http.post(
Uri.parse(TERM1 + sid + '&sess=' + sess + '&term=' + term),
headers: {"Content-Type": "application/json"},
);
if (response.statusCode == 200) {
print("reached");
//Map<List, dynamic> resposne = jsonDecode(response.body);
setState(() {
result1 = [] as Map;
result1 = jsonDecode(response.body);
resultLoading = false;
//here Im trying to extract the name of the subject in the json which is my problem
print(result1['result'][0]['subject']);
});
} else {
print("Not reached");
}
}
如何在颤振中提取?
我需要使用 List 还是 Map
【问题讨论】:
-
你能发布你想要得到的最终结果吗?你的代码显示了你到目前为止的尝试?
-
@Andrija 我已经更新了我的问题以包括我尝试过的内容
标签: flutter