关于数据表源数据访问

时间:2018-10-04 11:30:01

标签: javascript php jquery

我已经使用datatable ajax调用列出了我在ajax调用中收到了以下json数据:

{ 
    "sEcho":1,
    "iTotalRecords":"1",
    "iTotalDisplayRecords":"1",
    "aaData":[
        ["Demo to Mam","2"]
    ],
    "countOfTotalRecords":2
}

如何在视图页面上使用countOfTotalRecords var值?

2 个答案:

答案 0 :(得分:1)

您必须使用json_decode解码JSON数据,然后有了一个对象。看起来像这样:

$json = '{"sEcho":1,"iTotalRecords":"1","iTotalDisplayRecords":"1","aaData":[["Demo to Mam","2"]],"countOfTotalRecords"
:2}';

$decode = json_decode($json);

echo $decode->countOfTotalRecords; // this will display 2, regarding your data

答案 1 :(得分:1)

使用以下代码

 $str = '{"sEcho":1,"iTotalRecords":"1","iTotalDisplayRecords":"1","aaData":[["Demo to Mam","2"]],"countOfTotalRecords":2}';

 $arr = json_decode($str);

 $tcount = $arr->countOfTotalRecords;

 echo $tcount;