JsonParser用于解析从bugfree返回来的json信息:
package com.yunos.qa; import org.json.*; import java.util.Map; public class JsonParser { public static SessionInfo parseSessionInfo(String jsonResult) { System.out.println("sessionInfo: " + jsonResult); SessionInfo sessionInfo = new SessionInfo(); try { JSONObject jsonObj = new JSONObject(jsonResult); sessionInfo.setSessionName(jsonObj.getString("sessionname")); sessionInfo.setSessionId(jsonObj.getString("sessionid")); sessionInfo.setRand(jsonObj.getString("rand")); } catch(JSONException ex) { ex.printStackTrace(); } return sessionInfo; } public static boolean parseLoginResult(String jsonResult) { try { JSONObject jsonObj = new JSONObject(jsonResult); String status =jsonObj.getString("status"); return "success".equals(status); } catch(JSONException ex) { ex.printStackTrace(); } return false; } public static void parseModuleList(String jsonResult, Map<String,String> moduleName2OwnerMap) { try { JSONObject jsonObj = new JSONObject(jsonResult); JSONArray moduleList =jsonObj.getJSONArray("ModuleList"); int moduleCount = moduleList.length(); for(int i=0; i<moduleCount; i++) { JSONObject moduleObj = moduleList.getJSONObject(i); //System.out.println("module id:" + moduleObj.getString("id")); String moduleName = moduleObj.getString("name"); //System.out.println("module name:" + moduleName); //System.out.println("module product_id:" + moduleObj.getString("product_id")); //System.out.println("module grade:" + moduleObj.getString("grade")); //moduleObj.get //System.out.println("module parent_id:" + moduleObj.getString("parent_id")); //System.out.println("module full_path_name:" + moduleObj.getString("full_path_name")); //System.out.println("module display_order:" + moduleObj.getString("display_order")); //System.out.println("module owner_id:" + moduleObj.getString("owner_id")); String ownerName = moduleObj.getString("owner_name"); //System.out.println("module owner_name:" + ownerName); moduleName2OwnerMap.put(moduleName, ownerName); } } catch(JSONException ex) { ex.printStackTrace(); } } } |
SessionInfo用于会话信息:
package com.yunos.qa; public class SessionInfo { private String sessionName = ""; private String sessionId = ""; private String rand = ""; public String getSessionName() { return sessionName; } public void setSessionName(String sessionName) { this.sessionName = sessionName; } public String getSessionId() { return sessionId; } public void setSessionId(String sessionId) { this.sessionId = sessionId; } public String getRand() { return rand; } public void setRand(String rand) { this.rand = rand; } } |