1

嗨朋友们,我正在像这样从服务器(使用 kohana 框架 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 格式

提前致谢

4

2 回答 2

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);
}
于 2012-06-15T06:55:22.537 回答
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);
    }
于 2012-06-15T06:56:39.663 回答