import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
public static Map<String,Object> jsonToObject(Map<String, Object> jsonStr) {
JSONObject jsonObj;
Map<String, Object> outMap=null;
try {
if("".equals(jsonStr)) return outMap;
if(!"0".equals(jsonStr) && !"".equals(jsonStr)){
jsonObj = JSONObject.fromObject(jsonStr);
Iterator<String> nameItr = jsonObj.keys();
String name;
outMap = new HashMap<String, Object>();
while (nameItr.hasNext()) {
name = nameItr.next();
if("null".equals(jsonObj.getString(name))){
outMap.put(name, null);
}else{
outMap.put(name, jsonObj.get(name));
}
}
}
} catch (Exception e) {
log.error("Json字符串转换Map异常", e);
}
return outMap;
}
public static Map<String,Object> jsonToObject(String jsonStr) {
JSONObject jsonObj;
Map<String, Object> outMap=null;
try {
if("".equals(jsonStr)) return outMap;
if(!"0".equals(jsonStr) && !"".equals(jsonStr)){
jsonObj = JSONObject.fromObject(jsonStr);
Iterator<String> nameItr = jsonObj.keys();
String name;
outMap = new HashMap<String, Object>();
while (nameItr.hasNext()) {
name = nameItr.next();
if("null".equals(jsonObj.getString(name))){
outMap.put(name, null);
}else{
outMap.put(name, jsonObj.get(name));
}
}
}
} catch (Exception e) {
log.error("Json字符串转换Map异常", e);
}
return outMap;
}