Json字符串内容比较-超实用版

背景

之前有类似接口diff对比,数据对比的测试需求,涉及到json格式的数据对比,调研了几个大神们分享的代码,选了一个最符合自己需求的研究了下。

说明

这个对比方法,支持JsonObject和JsonArray类型的数据对比,支持:

  • 深度的对比:list变化(个数、内容)、层级结构变化

  • 字段的对比:新增、修改、删除数据可察觉,能找到对应的旧数据

  • 支持特定字段忽略对比

输出的对比结果格式为:

源码分为JsonCompareUtils, JsonAndMapSortUtils两个类,对比入口是compareTwoJson方法

核心逻辑在JsonCompareUtils类中,JsonAndMapSortUtils主要做过程中的数据排序功能,相对独立。

 上源码:

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;

import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Stream;

public class JsonCompareUtils {
    //标志位:对json报文中含有JsonArray类型的数据是否进行排序
    private static boolean isSort;

    private Map<String, Object> oldJsonToMap = new LinkedHashMap<>();
    private Map<String, Object> newJsonToMap = new LinkedHashMap<>();

    //每一个实体里的排序字段
    private static Map<String, String> filedNameMap = new HashMap<>();

    static {
        filedNameMap.put("ojb1", "id");
        filedNameMap.put("ojb2", "id");
    }

    //可以跳过比对的字段
    private static String[] skipCompareFiledNameMap = {"createTime"};

    /**
     * 两json报文比对入口
     *
     * @param oldJsonStr
     * @param newJsonStr
     * @return
     */
    public String compare2Json(String oldJsonStr, String newJsonStr) {
        /**
         * 递归遍历json对象所有的key-value,以map形式的path:value进行存储
         * 然后对两个map进行比较
         */
        convertJsonToMap(JSON.parseObject(oldJsonStr), "", false);
        convertJsonToMap(JSON.parseObject(newJsonStr), "", true);
        //获取比较结果
        Map<String, Object> differenceMap = compareTwoMaps(oldJsonToMap, newJsonToMap);
        String diffJsonResult = convertMapToJson(differenceMap);
        return diffJsonResult;
    }

    /**
     * 将json数据转换为map存储--用于后续比较map
     *
     * @param json
     * @param root
     * @param isNew 区别新旧报文
     */
    private void convertJsonToMap(Object json, String root, boolean isNew) {
        if (json instanceof JSONObject) {
            JSONObject jsonObject = ((JSONObject) json);
            Iterator iterator = jsonObject.keySet().iterator();
            while (iterator.hasNext()) {
                Object key = iterator.next();
                Object value = jsonObject.get(key);
                String newRoot = "".equals(root) ? key + "" : root + "." + key;
                fillInResultMap(value, newRoot, isNew);
            }
        } else if (json instanceof JSONArray) {
            JSONArray jsonArray = (JSONArray) json;
            //将jsonArray进行排序
            if (isSort) {
                //需要排序
                String sortEntityName = root.substring(root.lastIndexOf(".") + 1);
                //需要排序 获取排序字段
                String sortFiledName = filedNameMap.get(sortEntityName);
                if (!StringUtils.isEmpty(sortFiledName)) {
                    jsonArray = JsonAndMapSortUtils.jsonArrayToSort(jsonArray, sortFiledName, true);
                }
            }
            final JSONArray jsonArray1 = jsonArray;
            Stream.iterate(0, integer -> integer + 1).limit(jsonArray1.size()).forEach(index -> {
                Object value = jsonArray1.get(index);
                String newRoot = "".equals(root) ? "[" + index + "]" : root + ".[" + index + "]";
                fillInResultMap(value, newRoot, isNew);
            });
        }
    }

    /**
     * 封装json转map后的数据
     *
     * @param value
     * @param newRoot
     * @param isNew   区别新旧json
     */
    public void fillInResultMap(Object value, String newRoot, boolean isNew) {
        if (value instanceof JSONObject || value instanceof JSONArray) {
            convertJsonToMap(value, newRoot, isNew);
        } else {
            //设置跳过比对的字段,直接不装入map
            boolean check = ArrayUtils.contains(JsonCompareUtils.skipCompareFiledNameMap, newRoot);
            if (!check){
                if (!isNew) {
                    oldJsonToMap.put(newRoot, value);
                } else {
                    newJsonToMap.put(newRoot, value);
                }
            }
        }
    }

    /**
     * 比较两个map,将不同的数据以map形式存储并返回
     *
     * @param oldJsonMap
     * @param newJsonMap
     * @return
     */
    private Map<String, Object> compareTwoMaps(Map<String, Object> oldJsonMap, Map<String, Object> newJsonMap) {
        //1.将newJsonMap的不同数据装进oldJsonMap,同时删除oldJsonMap中与newJsonMap相同的数据
        newJsonMap.forEach((k, v) -> {
            Map<String, Object> differenceMap = new HashMap<>();
            if (oldJsonMap.containsKey(k)) {
                Object oldValue = oldJsonMap.get(k);
                if (v.equals(oldValue)) {
                    oldJsonMap.remove(k);
                } else {
                    differenceMap.put("oldValue", oldValue);
                    differenceMap.put("newValue", v);
                    oldJsonMap.put(k, differenceMap);
                }
            } else {
                differenceMap.put("oldValue", "no exists " + k);
                differenceMap.put("newValue", v);
                oldJsonMap.put(k, differenceMap);
            }
        });
        //2.统一oldJsonMap中newMap不存在的数据的数据结构,便于解析
        oldJsonMap.forEach((k, v) -> {
            if (!(v instanceof Map)) {
                Map<String, Object> differenceMap = new HashMap<>();
                differenceMap.put("oldValue", v);
                differenceMap.put("newValue", "no exists " + k);
                oldJsonMap.put(k, differenceMap);
            }
        });
        return oldJsonMap;
    }

    /**
     * 将已经找出不同数据的map根据key的层级结构封装成json返回
     *
     * @param map
     * @return
     */
    private String convertMapToJson(Map<String, Object> map) {
        JSONObject resultJSONObject = new JSONObject();
        for (Iterator<Map.Entry<String, Object>> it = map.entrySet().iterator(); it.hasNext(); ) {
            Map.Entry<String, Object> item = it.next();
            String key = item.getKey();
            Object value = item.getValue();
            String[] paths = key.split("\\.");
            int i = 0;
            //用於深度標識對象
            Object remarkObject = null;
            int indexAll = paths.length - 1;
            while (i <= paths.length - 1) {
                String path = paths[i];
                if (i == 0) {
                    //初始化对象标识
                    if (resultJSONObject.containsKey(path)) {
                        remarkObject = resultJSONObject.get(path);
                    } else {
                        if (indexAll > i) {
                            if (paths[i + 1].matches("\\[[0-9]+\\]")) {
                                remarkObject = new JSONArray();
                            } else {
                                remarkObject = new JSONObject();
                            }
                            resultJSONObject.put(path, remarkObject);
                        } else {
                            resultJSONObject.put(path, value);
                        }
                    }
                    i++;
                    continue;
                }
                //匹配集合对象
                if (path.matches("\\[[0-9]+\\]")) {
                    int startIndex = path.lastIndexOf("[");
                    int endIndext = path.lastIndexOf("]");
                    int index = Integer.parseInt(path.substring(startIndex + 1, endIndext));
                    if (indexAll > i) {
                        if (paths[i + 1].matches("\\[[0-9]+\\]")) {
                            while (((JSONArray) remarkObject).size() <= index) {
                                if (((JSONArray) remarkObject).size() == index) {
                                    ((JSONArray) remarkObject).add(index, new JSONArray());
                                } else {
                                    ((JSONArray) remarkObject).add(null);
                                }
                            }
                        } else {
                            while (((JSONArray) remarkObject).size() <= index) {
                                if (((JSONArray) remarkObject).size() == index) {
                                    ((JSONArray) remarkObject).add(index, new JSONObject());
                                } else {
                                    ((JSONArray) remarkObject).add(null);
                                }
                            }
                        }
                        remarkObject = ((JSONArray) remarkObject).get(index);
                    } else {
                        while (((JSONArray) remarkObject).size() <= index) {
                            if (((JSONArray) remarkObject).size() == index) {
                                ((JSONArray) remarkObject).add(index, value);
                            } else {
                                ((JSONArray) remarkObject).add(null);
                            }
                        }
                    }
                } else {
                    if (indexAll > i) {
                        if (paths[i + 1].matches("\\[[0-9]+\\]")) {
                            if (!((JSONObject) remarkObject).containsKey(path)) {
                                ((JSONObject) remarkObject).put(path, new JSONArray());
                            }
                        } else {
                            if (!((JSONObject) remarkObject).containsKey(path)) {
                                ((JSONObject) remarkObject).put(path, new JSONObject());
                            }
                        }
                        remarkObject = ((JSONObject) remarkObject).get(path);
                    } else {
                        ((JSONObject) remarkObject).put(path, value);
                    }
                }
                i++;
            }
        }
        return JSON.toJSONString(resultJSONObject);
    }

    public boolean isSort() {
        return isSort;
    }

    public void setSort(boolean sort) {
        isSort = sort;
    }

    public static void main(String[] args) {
        String oldStr = "{\"abilityLevel\":\"2020101240000000000002\",\"activityId\":\"202208301413310000412\",\"addLibTime\":1662083360000,\"ansKnowModelIds\":\"1#201812051814150000475\",\"answer\":\"AB\",\"ascriptionItemLib\":\"0\",\"attributeList\":[{\"content\":\"<p>A</p>\",\"id\":\"202209020949170005783\",\"itemId\":\"202209020949150001521\",\"knowModelRelId\":\"201812051814150000475\",\"name\":\"A\",\"sort\":1,\"type\":\"option\"},{\"content\":\"<p style=\\\"font-family:&#39;Times New Roman&#39;,&#39;宋体&#39;;font-size:12pt;padding:0;margin:0;\\\">B</p>\",\"id\":\"202209020949170005784\",\"itemId\":\"202209020949150001521\",\"name\":\"B\",\"sort\":2,\"type\":\"option\"},{\"content\":\"<p style=\\\"font-family:&#39;Times New Roman&#39;,&#39;宋体&#39;;font-size:12pt;padding:0;margin:0;\\\">C</p>\",\"id\":\"202209020949170005785\",\"itemId\":\"202209020949150001521\",\"name\":\"C\",\"sort\":3,\"type\":\"option\"},{\"content\":\"<p style=\\\"font-family:&#39;Times New Roman&#39;,&#39;宋体&#39;;font-size:12pt;padding:0;margin:0;\\\">D</p>\",\"id\":\"202209020949170005786\",\"itemId\":\"202209020949150001521\",\"name\":\"D\",\"sort\":4,\"type\":\"option\"},{\"content\":\"11\",\"createTime\":1662083368000,\"createTimeString\":\"2022-09-02 09:49:28\",\"creater\":\"10001\",\"id\":\"202209020949170005787\",\"itemId\":\"202209020949150001521\",\"name\":\"大纲依据\",\"searchFlag\":\"1\",\"sort\":1,\"subItemTypeAttrId\":\"100041\",\"type\":\"expandAttr\"},{\"content\":\"11\",\"createTime\":1662083370000,\"createTimeString\":\"2022-09-02 09:49:30\",\"creater\":\"10001\",\"id\":\"202209020949280005788\",\"itemId\":\"202209020949150001521\",\"name\":\"教材依据\",\"searchFlag\":\"1\",\"sort\":2,\"subItemTypeAttrId\":\"100042\",\"type\":\"expandAttr\"},{\"content\":\"11\",\"createTime\":1662083371000,\"createTimeString\":\"2022-09-02 09:49:31\",\"creater\":\"10001\",\"id\":\"202209020949290005789\",\"itemId\":\"202209020949150001521\",\"name\":\"关键字\",\"searchFlag\":\"1\",\"sort\":3,\"subItemTypeAttrId\":\"100043\",\"type\":\"expandAttr\"}],\"auditCount\":0,\"auditStatus\":0,\"childItemList\":[],\"createTime\":1662083350000,\"createTimeString\":\"2022-09-02 09:49:10\",\"creater\":\"10001\",\"delFlag\":\"0\",\"difficult\":\"3\",\"id\":\"202209020949150001521\",\"isComposite\":0,\"isTopVersion\":0,\"itemCode\":\"KJCJ202209020949140001501\",\"itemContent\":\"<p style=\\\"font-family:&#39;Times New Roman&#39;,&#39;宋体&#39;;font-size:12pt;padding:0;margin:0;\\\">2.<span style=\\\"color: #333333; font-family: Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif; font-size: 14px; text-align: justify; background-color: #FFFFFF;\\\">按照并购双方行业相关性划分,判断并购类型(横向并购or混合并购)</span></p>\",\"itemKnowledgeList\":[{\"id\":\"202209020949300001537\",\"itemId\":\"202209020949150001521\",\"knowledgeId\":\"1240004\",\"knowledgeStr\":\"2020年经济法基础/第一章总论/第一节法律基础/一、法和法律/(一)法和法律的概念\",\"level\":\"1\",\"pid\":\"202209020946580001519\"}],\"itemLevel\":1,\"itemSource\":\"202208301413310000412\",\"itemTypeId\":\"4\",\"itemVersion\":\"1\",\"keyWord\":\"\",\"knowledgeId\":\"1240004\",\"knowledgeStr\":\"2020年经济法基础/第一章总论/第一节法律基础/一、法和法律/(一)法和法律的概念\",\"knowledgeSyllabusName\":\"2020年经济法基础\",\"lockStatus\":1,\"modifyChlidItems\":[],\"paperCount\":0,\"paperItemRelation\":{},\"paperStructure\":{},\"parentId\":\"202209020946580001519\",\"processedItemContent\":\"<p style=\\\"font-family:&#39;Times New Roman&#39;,&#39;宋体&#39;;font-size:12pt;padding:0;margin:0;\\\">2.<span style=\\\"color: #333333; font-family: Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif; font-size: 14px; text-align: justify; background-color: #FFFFFF;\\\">按照并购双方行业相关性划分,判断并购类型(横向并购or混合并购)</span></p>\",\"score\":2,\"sort\":2,\"sourceType\":\"2\",\"structId\":\"\",\"subItemTypeId\":\"20180228155501000004\",\"subjectId\":\"4\",\"updateTime\":1662083350000,\"updateTimeString\":\"2022-09-02 09:49:10\",\"updater\":\"10001\"}";
        String newStr = "{\"abilityLevel\":\"2020101240000000000002\",\"activityId\":\"202208301413310000412\",\"addLibTime\":1662083360000,\"analysis\":\"\",\"ansKnowModelIds\":\"1#201812051814150000475\",\"answer\":\"AB\",\"ascriptionItemLib\":\"0\",\"attributeList\":[{\"content\":\"<p>A</p>\",\"id\":\"202209021135210005855\",\"itemId\":\"202209020949150001521\",\"knowModelRelId\":\"201812051814150000475\",\"name\":\"A\",\"sort\":1,\"type\":\"option\"},{\"content\":\"<p style=\\\"font-family:&#39;Times New Roman&#39;,&#39;宋体&#39;;font-size:12pt;padding:0;margin:0;\\\">B</p>\",\"id\":\"202209021135210005856\",\"itemId\":\"202209020949150001521\",\"name\":\"B\",\"sort\":2,\"type\":\"option\"},{\"content\":\"<p style=\\\"font-family:&#39;Times New Roman&#39;,&#39;宋体&#39;;font-size:12pt;padding:0;margin:0;\\\">C</p>\",\"id\":\"202209021135210005857\",\"itemId\":\"202209020949150001521\",\"name\":\"C\",\"sort\":3,\"type\":\"option\"},{\"content\":\"<p style=\\\"font-family:&#39;Times New Roman&#39;,&#39;宋体&#39;;font-size:12pt;padding:0;margin:0;\\\">D</p>\",\"id\":\"202209021135210005858\",\"itemId\":\"202209020949150001521\",\"name\":\"D\",\"sort\":4,\"type\":\"option\"},{\"content\":\"11\",\"createTime\":1662089721000,\"createTimeString\":\"2022-09-02 11:35:21\",\"creater\":\"10001\",\"id\":\"202209021135210005859\",\"itemId\":\"202209020949150001521\",\"name\":\"大纲依据\",\"searchFlag\":\"1\",\"sort\":1,\"subItemTypeAttrId\":\"100041\",\"type\":\"expandAttr\"},{\"content\":\"11\",\"createTime\":1662089721000,\"createTimeString\":\"2022-09-02 11:35:21\",\"creater\":\"10001\",\"id\":\"202209021135210005860\",\"itemId\":\"202209020949150001521\",\"name\":\"教材依据\",\"searchFlag\":\"1\",\"sort\":2,\"subItemTypeAttrId\":\"100042\",\"type\":\"expandAttr\"},{\"content\":\"11\",\"createTime\":1662089722000,\"createTimeString\":\"2022-09-02 11:35:22\",\"creater\":\"10001\",\"id\":\"202209021135210005861\",\"itemId\":\"202209020949150001521\",\"name\":\"关键字\",\"searchFlag\":\"1\",\"sort\":3,\"subItemTypeAttrId\":\"100043\",\"type\":\"expandAttr\"}],\"auditCount\":0,\"auditStatus\":0,\"childItemList\":[],\"createTime\":1662083350000,\"createTimeString\":\"2022-09-02 09:49:10\",\"creater\":\"10001\",\"delFlag\":\"0\",\"difficult\":\"5\",\"id\":\"202209020949150001521\",\"isComposite\":0,\"isTopVersion\":0,\"itemCode\":\"KJCJ202209020949140001501\",\"itemContent\":\"<p style=\\\"font-family:&#39;Times New Roman&#39;,&#39;宋体&#39;;font-size:12pt;padding:0;margin:0;\\\">2.<span style=\\\"color: #333333; font-family: Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif; font-size: 14px; text-align: justify; background-color: #FFFFFF;\\\">按照并购双方行业相关性划分,判断并购类型(横向并购or混合并购)</span></p>\",\"itemKnowledgeList\":[{\"id\":\"202209021135230001557\",\"itemId\":\"202209020949150001521\",\"knowledgeId\":\"1240004\",\"knowledgeStr\":\"2020年经济法基础/第一章总论/第一节法律基础/一、法和法律/(一)法和法律的概念\",\"level\":\"1\",\"pid\":\"202209020946580001519\"}],\"itemLevel\":1,\"itemSource\":\"202208301413310000412\",\"itemTypeId\":\"4\",\"itemVersion\":\"2\",\"keyWord\":\"\",\"knowledgeId\":\"1240004\",\"knowledgeStr\":\"2020年经济法基础/第一章总论/第一节法律基础/一、法和法律/(一)法和法律的概念\",\"knowledgeSyllabusName\":\"2020年经济法基础\",\"lockStatus\":1,\"modifyChlidItems\":[],\"paperCount\":0,\"paperItemRelation\":{},\"paperStructure\":{},\"parentId\":\"202209020946580001519\",\"processedItemContent\":\"<p style=\\\"font-family:&#39;Times New Roman&#39;,&#39;宋体&#39;;font-size:12pt;padding:0;margin:0;\\\">2.<span style=\\\"color: #333333; font-family: Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif; font-size: 14px; text-align: justify; background-color: #FFFFFF;\\\">按照并购双方行业相关性划分,判断并购类型(横向并购or混合并购)</span></p>\",\"score\":2,\"sort\":2,\"sourceType\":\"2\",\"structId\":\"\",\"subItemTypeId\":\"20180228155501000004\",\"subjectId\":\"4\",\"updateTime\":1662089720000,\"updateTimeString\":\"2022-09-02 11:35:20\",\"updater\":\"10001\"}";
        System.out.println(new JsonCompareUtils().compare2Json(oldStr, newStr));
        System.out.println("\n========测试复杂json的比对============");
    }
}

JsonAndMapSortUtils 用于jsonArray排序
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import sun.misc.ASCIICaseInsensitiveComparator;

import java.util.*;

public class JsonAndMapSortUtils {

    /**
     * map排序
     * @param map
     * @param keySort
     * @param <k>
     * @param <v>
     * @return
     */
    public static <k,v> List mapByKeyToSort(Map<k,v> map , final Comparator keySort){
        List<Map.Entry<k,v>> entryList = new ArrayList<>(map.entrySet());
        Collections.sort(entryList, (o1, o2) -> keySort.compare(o1.getKey(),o2.getKey()));
        System.out.println("排序=====");
        entryList.forEach(m->{
            System.out.println(m.getKey()+"===>"+m.getValue());
        });
        return entryList;
    }

    /**
     * JSONArray排序
     * @param jsonArray
     * @param fildName
     * @param isAsc
     * @return
     */
    public static JSONArray jsonArrayToSort(JSONArray jsonArray,final String fildName,final boolean isAsc){
        JSONArray afterSortJsonArray = new JSONArray();
        List<JSONObject> objectList = new ArrayList<>();
        jsonArray.forEach(obj ->{
            objectList.add((JSONObject)obj);
        });
        Collections.sort(objectList, (o1, o2) -> {
            String fildValueA = o1.getString(fildName);
            String fildValueB = o2.getString(fildName);
            if (isAsc){
                return fildValueA.compareTo(fildValueB);
            }
            return fildValueB.compareTo(fildValueA);
        });
        objectList.forEach(obj->{
            afterSortJsonArray.add(obj);
        });
        return afterSortJsonArray;
    }

    /**
     *准备map测试数据
     */
    public static Map<String,String> getMapData(){
        LinkedHashMap<String,String> map = new LinkedHashMap<>();
        map.put("key1","测试1");
        map.put("key3","测试3");
        map.put("key5","测试5");
        map.put("key2","测试2");
        map.put("key4","测试4");
        return map;
    }
    /**
     *准备json测试数据
     */
    public static JSONArray getJsonArrayData(){
        JSONArray jsonArray = new JSONArray();
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("userId","1001");
        jsonObject1.put("name","测试1");
        jsonArray.add(jsonObject1);

        JSONObject jsonObject3 = new JSONObject();
        jsonObject3.put("userId","1003");
        jsonObject3.put("name","测试3");
        jsonArray.add(jsonObject3);

        JSONObject jsonObject2 = new JSONObject();
        jsonObject2.put("userId","1002");
        jsonObject2.put("name","测试2");
        jsonArray.add(jsonObject2);

        return jsonArray;
    }
     
    public static void main(String[] args) {
        Map<String,String> map = JsonAndMapSortUtils.getMapData();
        JSONArray jsonArray = JsonAndMapSortUtils.getJsonArrayData();
        List afterSortMap = JsonAndMapSortUtils.mapByKeyToSort(map,new ASCIICaseInsensitiveComparator());

        JSONArray afterSortJsonArray_isAsc = JsonAndMapSortUtils.jsonArrayToSort(jsonArray,"userId",true);
        JSONArray afterSortJsonArray_noAsc = JsonAndMapSortUtils.jsonArrayToSort(jsonArray,"userId",false);

        System.out.println("map排序前:"+map);
        System.out.println("map排序后:"+afterSortMap+"\n");

        System.out.println("JsonArray排序前:"+jsonArray);
        System.out.println("JsonArray排序后==》升序:"+afterSortJsonArray_isAsc);
        System.out.println("JsonArray排序后==》降序:"+afterSortJsonArray_noAsc);
    }

}


源码走读
整个源码调用链路如下图,简单来说过程就是:object拆分解析-新旧数据逐个对比-结果信息组装三个步骤

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
通信相关 1.C#HttpHelper,Httpwebrequest,请求时无视编码,无视证书,无视Cookie,网页抓取 主要是实现了HTTP协议的GET|POST请求时的无视编码,无视证书,设置代理,自动获取Cookie的功能。 访问数据库相关 1.SqlHelper类 使用C#实现对Sql数据库的操作,执行存储过程,Sql语句,返回影响行数,返回DateTable,DataSet,DataReader,以及表集等方法。实现多个数据库的切换功能。功能强大,希望大家喜欢 2.一个操作Sql2005数据库的类(备份,还原,分离,附加,添加删除用户等操作) 这主要是为了让大家练手的,他使用C#代 码的方法实现了对数据的 备份,还原,分离,附加,添加和删除用户等操作 帮助类 1.最新的Functions 类 这里面实现了很多的帮助方法,比如正则验证,加密,解密,MD5加密,字符串的处理等操作。 2.最新的 PageValidate 类 主要是实现了验证,是否为空,是否为数字等。 3.JavascriptHelp 帮助输出简单的JS代码 4.最新的皮肤帮助类 UI_Misc_Helper JavaScript|Jquery相关 1.jQuery.cookie帮助类 访问系统相关 1.C#计算机信息类ComputerInfo 实现了计算机的信息获取功能,计算机名,IP,硬盘信息,网卡信息,操作系统信息等 2.Api_Win32_Mac类工具包 一个Win32的Api包,实现了大部分的Api操作帮助方法 3.在c#程序中放音乐的帮助类 使用C#播放音乐的帮助类,只需要调用方法就可以放音乐了 GDI+相关,图像相关1.生成缩略图的类文件SmallImage 一个把图片生成缩略图的类,可以设置大小,非常好用,希望大家喜欢哦。 C#基础类库1.Chart图形 Assistant创建显示图像的标签和文件 OWCChart统计图的封装类 2.Cookie&Session;&Cache;缓存帮助类 CacheHelper C#操作缓存的帮助类,实现了怎么设置缓存,怎么取缓存,怎么清理缓存等方法,只需要调用方法就可以实现 CookieHelper C#操作Cookie的帮助类,添加Cookie,删除Cookie,修改Cookie,清理Cookie SessionHelper C#关于Session的操作,获取Session,设置Session,删除Session使用方便,只需要调用方法就可以了 SessionHelper2 C#关于Session的一些高级操作,比如取Session对象,取Session数据等等 3.CSV文件转换 CsvHelper CSV文件导入DataTable和DataTable导出到Csv文件等操作 4.DEncrypt 加密/解密帮助类 DEncrypt C#DEncrypt加密/DEncrypt解密帮助类 ,多种方式,可以设置Key DESEncrypt C#DESEncrypt加密/DESEncrypt解密帮助类 ,多种方式,可以设置Key Encrypt C#Encrypt--Encrypt加密/Encrypt解密/附加有MD5加密,个人感觉很不错的一个加密类 HashEncode 哈希加密帮助类,得到随机哈希加密字符串,随机哈希数字加密等 MySecurity MySecurity--Security安全加密/Security Base64/Security文件加密,以及一些常用的操作方法 RSACryption RSACryption--RSA加密/RSA解密字符串 RSA加密应用最多是银行接口,这里的方法可以直接使用哦 5.FTP操作类 FTPClient   FTPClient--FTP操作帮助类,FTP上传,FTP下载,FTP文件操作,FTP目录操作 FTPHelper FTPHelper-FTP帮助类,FTP常用操作方法,添加文件,删除文件等 FTPOperater FTP操作帮助类,方法比较多,比较实用 6.JS操作类 JsHelper JsHelper--Javascript操作帮助类,输出各种JS方法,方便不懂JS的人使用,减少代码量 7.JSON 转化类 ConvertJson List转成
EasyASP是一个方便快速开发ASP的类,其中包含了数据库控制类Easp.db,具有同时对一个或多个数据库进行各类操作、调用MSSQL存储过程及记录集分页等功能。EasyASP同时提供了大量实用的ASP通用过程及方法,可以简化大部分的ASP操作。EasyASP目前提供下载的是VBScript。 EasyASP 2.1 UTF-8 更新日志: 新增Easp.Include方法,完美实现了ASP的动态包含,且支持ASP源码中无限级层次的。 新增Easp.GetInclude方法,用于获取ASP文件运行的结果或获取html文件等文本文件的源码。 新增Easp.Charset属性,用于设置Easp.Include方法和Easp.getInclude方法载入文件的编码。 新增Easp.ConfirmUrl方法,用于输出确认信息框并根据选择进行Url跳转。 新增Easp.HtmlFormat方法,用于对html文本进行简单的格式化(仅转换空格和换行为可见)。 新增Easp.RegReplaceM方法,用于正则替换的多行模式。 新增Easp.RegMatch方法,用于正则匹配的编组捕获。 新增Easp.IsInstall方法,用于检测系统是否安装了某个组件。 [db]新增Easp.db.QueryType属性,可设置用ADO的RecordSet还是Command方式获取记录集。 [db]新增Easp.db.GetRandRecord方法,用于取得指定数量的随机记录集。 [db]新增Easp.db.Exec方法,用于执行SQL语句或者返回Command方式查询的记录集。 优化Easp.DateTime方法,格式化为时间差时的显示更人性化。 优化Easp.RandStr和Easp.db.RandStr方法,提供更强大更人性化的随机字符串和随机数生成功能。 修正Easp.GetUrlWith方法第一个参数为空时生成的新URL出错的Bug。 修正Easp.GetApp方法无法获取缓存数据的Bug。 修正Easp.AlertUrl跳转前会继续执行服务器端代码的Bug。 修正v2.1beta中Easp.JsEncode和Easp.db.Json方法会报“类型不匹配”错误的Bug。 修正v2.1beta中Easp.RandStr和Easp.db.RandStr的一个Bug。 [db]优化Easp.db.AddRecord方法,现在仅当指定了ID字段的名称时才返回新增的记录ID号。(影响以前本) [db]修正分页下拉框中页面数量小于jumplong配置时出现负数的Bug。 EasyASP的特点: [数据库] 能方便的实现一个或多个数据库的增、删、改等控制操作。 [数据库] 对数据库字段进行操作时可以不用考虑字段值数据类型的差别(如文本字段不用加单引号)。 [数据库] 自带记录集分页和调用存储过程分页功能,拥有功能丰富的可完全自定义配置及调用。 [数据库] 能方便的执行带各种参数的MSSQL存储过程并返回多个值或多个记录集。 [数据库] 完善的数据库操作容错功能,能即时输出出错SQL语句方便调试。 [数据库] 在使用已经存在的数据库连接对象时能自动判断数据库类型。 [数据库] 专为Ajax设计的数据获取方式及输出Json格式数据。 [数据库] 能有效防止SQL注入。 [ASP] 自带大量的ASP通用过程及方法,简化大部分ASP操作。 [ASP] 完美实现ASP文件的动态载入,并支持无限级的ASP原生include。 [ASP] 自带数据类型验证及服务器端表单验证功能。 [ASP] 能轻松实现页面地址获取并对URL参数进行过滤以及替换。 [工具] 具有专为EasyASP开发的适用于Dreamweaver CS3 和 CS4 的代码高亮及代码提示扩展插件。 [工具] 具有完善的帮助手册及大量应用实例。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值