java解析json字符串
/**
* json字符串解析
*
* @param JSONString
* 原始json字符串
* @return HashMap
* @throws JSONException
*/
public static HashMap parseJSONString(String JSONString)
throws JSONException {
HashMap resultMap = new HashMap();
JSONArray jsonArray = new JSONArray();
try {
// 直接把JSON字符串转化为一个JSONObject对象
JSONObject person = new JSONObject(JSONString);
System.out.println("the info is "
+ person.getJSONArray("infoBaseTime").toString());
jsonArray = person.getJSONArray("infoBaseTime");
} catch (JSONException e) {
e.printStackTrace();
}
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
Map map = new HashMap();
for (Iterator> iter = jsonObject.keys(); iter.hasNext();) {
String key = (String) iter.next();
String value = jsonObject.get(key).toString();
resultMap.put(key, value);
System.out.println("key is " + key + " value is " + value);
}
// rsList.add(map);
}
printHash(resultMap);
return resultMap;
}