获得所需的json格式

时间:2012-06-15 06:53:47

标签: php kohana-3 json

朋友们,我正在从服务器(使用kohana framework 3.0)获取json,就像这样......

 {
        "aaData": [
            {
                "regNo": "1",
                "regDate": "2025-05-12",
                "patientName": "Ratna",
                "address": "saasgasgasga",
                "city": "Hyderabad",
                "phno": "2147483647",
                "mrgStatus": "single",
                "religion": "1",
                "gender": "male",
                "fathername": "Yohan",
                "status": "2",
                "age": "25"
            }
        ]
    }

但我想要格式

{
        "aaData": [
            [
               "1",
               "2025-05-12",
               "Ratna",
               "saasgasgasga",
               "Hyderabad",
                "2147483647",
                "single",
                "1",
                "male",
                "Yohan",
                "2",
                "25"
            ]
        ]
    }

kohana控制器

public function action_index()
    {
         $table = new Model_patientdetails();
         $log =$table ->get_all();
         $output = array("aaData" => $log);
         $this->auto_render=false;
         echo json_encode($output);
    }

请建议我如何获得所需的json格式

提前致谢

2 个答案:

答案 0 :(得分:1)

使用 array_values()仅获取值

public function action_index()
{
     $table = new Model_patientdetails();
     $log =$tab ->get_all();
     foreach($log as &$l)
     {
        $l = array_values($l)
     }
     $output = array("aaData" => $log);
     $this->auto_render=false;
     echo json_encode($output);
}

答案 1 :(得分:0)

我的代码中没有找到$log1变量,因此我认为它是$log

你可以这样做:

public function action_index()
    {
         $table = new Model_patientdetails();
         $log = $tab->get_all();
         $output = array("aaData" => array_values($log));
         $this->auto_render=false;
         echo json_encode($output);
    }