package com.tencent.census.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import java.util.Map;
public final class JsonUtil {
/**
* 私有构造
*
*/
private JsonUtil() {
}
/**
* <Object转换成JSON字符串>
* <功能详细描述>
*
* @param obj
* @return
* @see [类、类#方法、类#成员]
*/
public static String obj2json(Object obj) {
return JSON.toJSONString(obj);
}
/**
* <json字符串转Map>
* <功能详细描述>
*
* @param json
* @return
* @see [类、类#方法、类#成员]
*/
public static Map<String, Object> json2Map(String json) {
try {
return JSON.parseObject(json);
} catch (Exception e) {
//LOGGER.error("json转换失败! Json String: " + json + ", Error:" + e.getMessage());
return null;
}
}
/**
* Json转换String
* @param map
* @return
*/
public static String getJson(Map<String,Object> map){
JSONObject json = new JSONObject();
if(map != null || map.size() > 0){
json.putAll(map);
}
return JSONObject.toJSONString(json);
}
}