/**
* 将json字符串转换成List<Map>(List中是Map类型)
* @param productCodes sjon字符串 格式为 ({a:1,b:2},{c:3,d:4})
* @return List<Map>
*/
public static List<Map> jsonToList(String json) {
List<Map> listMap = new ArrayList<Map>();
String JSON = json.substring(1, json.length() - 1);
JSON = JSON.replaceAll("},", "}^");
StringTokenizer strTokenizer = new StringTokenizer(JSON, "^");
while (strTokenizer.hasMoreTokens()) {
String token = strTokenizer.nextToken();
Map paraMap = JsonUtil.getMap4Json(token);
listMap.add(paraMap);
}
return listMap;
}
public static Map getMap4Json(String jsonString) {
JSONObject jsonObject = JSONObject.fromObject(jsonString);
Iterator keyIter = jsonObject.keys();
String key;
Object value;
Map valueMap = new HashMap();
while (keyIter.hasNext()) {
key = (String) keyIter.next();
value = String.valueOf(jsonObject.get(key));
valueMap.put(key, value);
}
return valueMap;
}