// 解析错误或提示性的JSON数据 private static Map<String, Object> toMap(String jsonString) throws Exception { JSONObject jsonObject = new JSONObject("{mess:" + jsonString + "}"); Map item = new HashMap(); Iterator iter = jsonObject.keys(); String key = null, value = null; while (iter.hasNext()) { key = (String) iter.next(); value = jsonObject.getString(key).toString(); item.put(key, value); } return item; }
// 解析正确返回的json数据 private static ArrayList<HashMap<String, Object>> JSONAnalysis(String jsonString) throws JSONException { JSONArray jsonArray = new JSONArray(jsonString); ArrayList<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>(); list.clear(); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); HashMap<String, Object> map = new HashMap<String, Object>(); Iterator iter = jsonObject.keys(); String key = null, value = null; while (iter.hasNext()) { key = (String) iter.next(); value = jsonObject.getString(key); map.put(key, value); } list.add(map); } return list; }