0

给定一个数组:

{"aaData":[
    {"first":2, "second":"4", "third":"5"},
    {"first":4, "second":"56", "third":"67"}
    {"first":3, "second":"55", "third":"8"}],
 "sEcho":1, "iTotalRecords":1, "iTotalDisplayRecords":1}

当我阅读并返回它时:

$json_string = 'my_url';
$jsondata = file_get_contents($json_string);
$obj = json_decode($jsondata);
return array('sEcho'=> 1, 
       'iTotalRecords'=> 5, 
       'iTotalDisplayRecords'=> 5, 
       'aaData'=>array(
                     array($obj->aaData[0]->first, 
                         $obj->aaData[0]->second,
                         $obj->aaData[0]->third)
                 )
        );

我只得到第一项aaData{"first":2,"second":"4","third":"5"}

但我需要从中获取所有内容my_url。我该怎么做?

4

1 回答 1

0

您已经尝试通过指定仅打印第一个数组值$obj->aaData[0]

您必须使用以下代码来获取所有值。

return array('sEcho'=> 1,
             'iTotalRecords'=> 5,
             'iTotalDisplayRecords'=> 5,
             'aaData'=>array(array($obj->aaData)));
于 2013-07-03T07:21:48.683 回答