private static Map map=new HashMap();
public static Map parserToMap(String s){
JSONObject json=JSONObject.fromObject(s);
Iterator keys=json.keys();
while(keys.hasNext()){
String key=(String) keys.next();
String value=json.get(key).toString();
if(value.startsWith("{")&&value.endsWith("}")){
map.put(key, parserToMap(value));
}else{
map.put(key, value);
}
}
return map;
}
s是JSON格式的字符串,如下所示
{'name':'test','data':[{'data1':1}, {'data2':2}], 'test':{'test':'test'}}