JQuery Datatable 请求数据解析 #yyds干货盘点#

Posted 梁云亮

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JQuery Datatable 请求数据解析 #yyds干货盘点#相关的知识,希望对你有一定的参考价值。

请求数据

[
    
        "name": "sEcho",
        "value": 1
    ,
    
        "name": "iColumns",
        "value": 6
    ,
    
        "name": "sColumns",
        "value": ",,,,,"
    ,
    
        "name": "iDisplayStart",
        "value": 0
    ,
    
        "name": "iDisplayLength",
        "value": 10
    ,
    
        "name": "mDataProp_0",
        "value": "id"
    ,
    
        "name": "sSearch_0",
        "value": ""
    ,
    
        "name": "bRegex_0",
        "value": false
    ,
    
        "name": "bSearchable_0",
        "value": true
    ,
    
        "name": "bSortable_0",
        "value": false
    ,
    
        "name": "mDataProp_1",
        "value": "id"
    ,
    
        "name": "sSearch_1",
        "value": ""
    ,
    
        "name": "bRegex_1",
        "value": false
    ,
    
        "name": "bSearchable_1",
        "value": true
    ,
    
        "name": "bSortable_1",
        "value": true
    ,
    
        "name": "mDataProp_2",
        "value": "name"
    ,
    
        "name": "sSearch_2",
        "value": ""
    ,
    
        "name": "bRegex_2",
        "value": false
    ,
    
        "name": "bSearchable_2",
        "value": true
    ,
    
        "name": "bSortable_2",
        "value": true
    ,
    
        "name": "mDataProp_3",
        "value": "info"
    ,
    
        "name": "sSearch_3",
        "value": ""
    ,
    
        "name": "bRegex_3",
        "value": false
    ,
    
        "name": "bSearchable_3",
        "value": true
    ,
    
        "name": "bSortable_3",
        "value": true
    ,
    
        "name": "mDataProp_4",
        "value": "status"
    ,
    
        "name": "sSearch_4",
        "value": ""
    ,
    
        "name": "bRegex_4",
        "value": false
    ,
    
        "name": "bSearchable_4",
        "value": true
    ,
    
        "name": "bSortable_4",
        "value": false
    ,
    
        "name": "mDataProp_5",
        "value": null
    ,
    
        "name": "sSearch_5",
        "value": ""
    ,
    
        "name": "bRegex_5",
        "value": false
    ,
    
        "name": "bSearchable_5",
        "value": true
    ,
    
        "name": "bSortable_5",
        "value": false
    ,
    
        "name": "sSearch",
        "value": ""
    ,
    
        "name": "bRegex",
        "value": false
    ,
    
        "name": "iSortCol_0",
        "value": 1
    ,
    
        "name": "sSortDir_0",
        "value": "desc"
    ,
    
        "name": "iSortingCols",
        "value": 1
    
]

封装代码

    public static Map<String, Object> init(String data) 
        Map<String, Object> map = new HashMap<>();
        try 
            JsonFactory jsonFactory = new JsonFactory();
            JsonParser jsonParser = jsonFactory.createParser(data);
            String key = "";
            String value = "";
            boolean flag = false;
            while (true) 
                JsonToken jsonToken = jsonParser.nextToken();
                if (jsonToken == JsonToken.END_ARRAY) 
                    break;
                
                String currentName = jsonParser.getCurrentName();

                if (currentName != null && currentName.equals("name")) 
                    jsonParser.nextToken();
                    key = jsonParser.getText();
                    flag = false;
                
                if (currentName != null && currentName.equals("value")) 
                    jsonParser.nextToken();
                    value = jsonParser.getText();
                    flag =false;
                    //去掉值为null、“”的字结果
                    if(value!=null && value.length()>1) 
                        flag = true;
                    
                
                if (flag) 
                    map.put(key, value);
                
            
         catch (Exception e) 
            e.printStackTrace();
        
        return map;
    

以上是关于JQuery Datatable 请求数据解析 #yyds干货盘点#的主要内容,如果未能解决你的问题,请参考以下文章

在 DataTable Delete 操作中多次发送 Ajax 请求 - ASP.NET、JQuery、Ajax

jquery datatable 实例操作

使用 Javascript 填充表数据时,jQuery Datatable 功能不起作用

为啥 jQuery dataTables 不能解析我的 JSON?

jQuery DataTable - 以预期的方式隐藏行

JSon 返回一串 HTML table 以显示在 jQuery datatable 的 fnopen 中