/**
* @方法描述: json字符串转换map
* 方法的重载方法名相同参数类型个数不同
*/
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) {
// TODO Auto-generated catch block
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) {
// TODO Auto-generated catch block
log.error("Json字符串转换Map异常", e);
}
return outMap;
}
json字符串转换map
最新推荐文章于 2024-05-23 11:39:56 发布