以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 解析JSON如何统计数据 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=186168) |
-- 作者:xluoping -- 发布时间:2023/4/10 17:55:00 -- 解析JSON如何统计数据 [{"id":"iddtd64","因数":["甲苯","乙苯","噪声"],"类别":["化学因素","物理因素"],"数量":5},{"id":"nnn6d4","因数":["二甲苯","乙苯","噪声"],"类别":["化学因素","物理因素"],"数量":10}] 如何用代码对以上JSON实例中统计出: 因数 甲苯:10 乙苯:15 噪声:15 二甲苯:10 类别 化学因素:15 物理因素:15 |
-- 作者:有点蓝 -- 发布时间:2023/4/10 20:09:00 -- dim json as string = "上面的json....." Dim ja As JArray = JArray.Parse(json) dim dict as new dictionary(of string,integer) Dim jo As JObject For i As Integer = 0 To ja.Count - 1 jo =ja(i) Dim ja2 As JArray = jo("因数") For j As Integer = 0 To ja2.Count - 1 if dict.containskey(ja2(j).tostring) then dict(ja2(j).tostring) += cint(jo("数量")) else dict.add(ja2(j).tostring,cint(jo("数量"))) end if Next Next For Each k As string In dict.Keys \'显示所有键及其对应的值
Output.Show(K & ":" & dict(k)) Next |