復雜json的解析:jsonobject與jsonArray的使用
阿新 • • 發佈:2017-08-17
string art 發起人 姓名 create 記錄 instance param rtt
String parameter = { success : 0, errorMsg : "錯誤消息", data : { total : "總記錄數", rows : [ { id : "任務ID", workName : "任務名稱", assigneeName : "經辦人姓名", name : "流程步驟名稱", processInstanceInitiatorName : "發起人", processInstanceStartTime : "發起時間", createTime : "到達時間", dueDate : "截止時間" }, { id : "ID", workName : "名稱", assigneeName : "經辦人", name : "流程", processInstanceInitiatorName : "發起人", processInstanceStartTime : "發起", createTime : "到達", dueDate : "截止" } ] } }; JSONObject jsonObject =JSONObject.fromObject(parameter); System.out.println("success:"+jsonObject.get("success")); System.out.println("errorMsg:"+jsonObject.get("errorMsg")); System.err.println("total:"+jsonObject.getJSONObject("data").get("total")); JSONObject data = jsonObject.getJSONObject("data"); JSONArray jsonArray = data.getJSONArray("row"); JSONObject row = null; for (int i = 0; i < jsonArray.size(); i++) { row = jsonArray.getJSONObject(i); System.out.println("id:"+row.get("id")); System.out.println("workName:"+row.get("workName")); System.out.println("assigneeName:"+row.get("assigneeName")); System.out.println("name:"+row.get("name")); System.out.println("processInstanceInitiatorName:"+row.get("processInstanceInitiatorName")); System.out.println("processInstanceStartTime:"+row.get("processInstanceStartTime")); System.out.println("createTime:"+row.get("createTime")); System.out.println("dueDate:"+row.get("dueDate")); }
復雜json的解析:jsonobject與jsonArray的使用