layui table 数据不符合规范怎么办?

提问 已结
7 81
levinsky
悬赏:20飞吻
版本:layui 2.4 浏览器:
按照开发文档,table 能接受的json格式为:
{"code":0,"msg":"","count":1000,"data":[{"id":10000,"username":"user-0","sex":"女","city":"城市-0","sign":"签名-0","experience":255,"logins":24,"wealth":82830700,"classify":"作家","score":57},{"id":10001,"username":"user-1","sex":"男","city":"城市-1","sign":"签名-1","experience":884,"logins":58,"wealth":64928690,"classify":"词人","score":27},{"id":10002,"username":"user-2","sex":"女","city":"城市-2","sign":"签名-2","experience":650,"logins":77,"wealth":6298078,"classify":"酱油","score":31},{"id":10003,"username":"user-3","sex":"女","city":"城市-3","sign":"签名-3","experience":362,"logins":157,"wealth":37117017,"classify":"诗人","score":68}]}
但是如果我只能获得到如此格式的json数据,该怎么办呢? 急急急!

{"ClientListDataResult":[{"code":0,"msg":"","count":1000,"data":[{"id":10000,"username":"user-0","sex":"女","city":"城市-0","sign":"签名-0","experience":255,"logins":24,"wealth":82830700,"classify":"作家","score":57},{"id":10001,"username":"user-1","sex":"男","city":"城市-1","sign":"签名-1","experience":884,"logins":58,"wealth":64928690,"classify":"词人","score":27},{"id":10002,"username":"user-2","sex":"女","city":"城市-2","sign":"签名-2","experience":650,"logins":77,"wealth":6298078,"classify":"酱油","score":31},{"id":10003,"username":"user-3","sex":"女","city":"城市-3","sign":"签名-3","experience":362,"logins":157,"wealth":37117017,"classify":"诗人","score":68}]}]}
谢谢谢~~
回帖
  • IDyun
    7天前
    table.render({
    elem: '#demp'
    ,url: ''
    ,parseData: function(res){ //res 即为原始返回的数据
    return {
    "code": res.ClientListDataResult.code, //解析接口状态
    "msg": res.ClientListDataResult.msg, //解析提示文本
    "count": res.ClientListDataResult.count, //解析数据长度
    "data": res.ClientListDataResult.data //解析数据列表
    };
    }
    //,…… //其他参数
    });
    0 回复
  • no,no,no, layui table 只能接受 {},这样的json数据,而不能接受{"xxxxxx":[{"code":0,"msg":"","count":1000,"data":[{"xxxxxxxxxxxxxxxx"}]......

    这样的数据,包含在里面的格式是正确的
    0 回复
  • table.render({
    elem: '#demp'
    ,url: ''
    ,parseData: function(res){ //res 即为原始返回的数据
    return {
    "code": res.ClientListDataResult.code, //解析接口状态
    "msg": res.ClientListDataResult.msg, //解析提示文本
    "count": res.ClientListDataResult.count, //解析数据长度
    "data": res.ClientListDataResult.data //解析数据列表
    };
    }
    //,…… //其他参数
    });
    我试过了,不行~~~似乎
    0 回复
  • res.ClientListDataResult[0].code
    0 回复
  • 谢谢月磊,搞定~~
    0 回复


  • 求帮助,像这样的格式怎么办?
    0 回复


  • 然后用原来的方法拿不到值,提示数据接口请求异常:error
    0 回复