• JsonTools 工具类


    import net.sf.json.JSONObject;
    
    public class JsonTools {
        public static JSONObject getJSONObject(String jData) {
            if (jData == null || jData.length() <= 0)
                return null;
            JSONObject obj = JSONObject.fromObject(jData);
            return obj;
        }
    
        public static <T> String getJsonString(T t) {
            JSONObject obj = JSONObject.fromObject(t);
            return obj.toString();
        }
    
        public static String getJsonValueByName(JSONObject object, String name) {
            if (object == null)
                return "--";
            String value = object.getString(name);
            if (null == value || "null".equalsIgnoreCase(value))
                value = "";
            return value;
        }
    
        public static String getJsonValueByName(String jData, String name) {
            if (jData == null || jData.length() <= 0)
                return "";
            JSONObject obj = JSONObject.fromObject(jData);
            String value = obj.getString(name);
            if (null == value || "null".equalsIgnoreCase(value))
                value = "";
            return value;
        }
    
        public static String getJsonValueNotNull(String jData, String name)
                throws Exception {
            if (jData == null || jData.length() <= 0)
                throw new Exception("获取请求数据[jsonData]为空");
            JSONObject obj = JSONObject.fromObject(jData);
            String value = obj.getString(name).trim();
            if (null == value || value.length() <= 0)
                throw new Exception("获取的数据对象[" + name + "]为空");
            return value;
        }
    
        @SuppressWarnings({ "rawtypes", "unchecked" })
        public static <T> T getJavaBean(String jData, Class clazz) {
            /*
             * JSONObject jsonObject = JSONObject.fromObject(jData); return (T)
             * JSONObject.toBean(jsonObject, clazz);
             */
            JSONObject jsonObject = JSONObject.fromObject(jData);
            return (T) JSONObject.toBean(jsonObject, clazz);
        }
    }
  • 相关阅读:
    Linux:less 命令
    Linux:more命令
    图解linux安装tomcat(附常用命令)
    Linux下安装tomcat
    Linux数字权限解释
    Tomcat配置远程调试
    CentOS 设置静态IP 方法
    oracle procedure存储过程
    【转】vector中erase()的使用注意事项
    strstr()函数的使用
  • 原文地址:https://www.cnblogs.com/zlw-xf/p/8395415.html
Copyright © 2020-2023  润新知