json解析

xiaoxiao2021-02-28  5

package com.yzx.crbt.test; import org.json.JSONArray; import org.json.JSONObject; public class text { public static void main(String[] args) { String s = "{'name':'张三','xingming':'男', " +"'testData':{" +"'tqq':{'Ceshichengji':'25.6','Dengji':'优秀','Pingjiadengji':'5','Ceshixiangmumingcheng':'坐位体前屈'}," +"'fys':{'Ceshichengji':'0.93','Dengji':'差','Pingjiadengji':'1','Ceshixiangmumingcheng':'选择反应时'}," +"'fwc':{'Ceshichengji':'5','Dengji':'差','Pingjiadengji':'1','Ceshixiangmumingcheng':'俯卧撑'}," +"'fhl':{'Ceshichengji':'517','Dengji':'差','Pingjiadengji':'1','Ceshixiangmumingcheng':'肺活量'}," +"'bydjzl':{'Ceshichengji':'5','Dengji':'稍差','Pingjiadengji':'2','Ceshixiangmumingcheng':'闭眼单脚站立'}," +"'zt':{'Ceshichengji':'74.8','Dengji':'优秀','Pingjiadengji':'5','Ceshixiangmumingcheng':'纵跳'}," +"'wl':{'Ceshichengji':'8.3','Dengji':'差','Pingjiadengji':'1','Ceshixiangmumingcheng':'握力'}," +"'tj':{'Ceshichengji':'28.6','Dengji':'差','Pingjiadengji':'1','Ceshixiangmumingcheng':'台阶指数'}," +"'bl':{'Ceshichengji':'23','Dengji':'差','Pingjiadengji':'0','Ceshixiangmumingcheng':'背力'}," +"'tz':{'Ceshichengji':'43','Dengji':'差','Pingjiadengji':'','Ceshixiangmumingcheng':'体重'}," +"'sg':{'Ceshichengji':'体重','Dengji':'差','Pingjiadengji':'5','Ceshixiangmumingcheng':'身高'}}}"; JSONObject job = new JSONObject(s); System.out.println(job.get("name")); System.out.println(job.get("xingming")); JSONObject testData = job.getJSONObject("testData"); JSONArray arr = testData.names(); for (int i = 0; i < arr.length(); i++) { JSONObject data=testData.getJSONObject((String) arr.get(i)); System.out.print(data.get("Ceshichengji")+"\t"); System.out.print(data.get("Dengji")+"\t"); System.out.print(data.get("Pingjiadengji")+"\t"); System.out.print(data.get("Ceshixiangmumingcheng")+"\t"); System.out.println(); } } }
转载请注明原文地址: https://www.6miu.com/read-2150092.html

最新回复(0)