2012-06-15 64 views
1

喜的朋友我得到來自服務器的JSON(使用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格式

在此先感謝

回答

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); 
} 
+0

我試過,但得到相同的輸出 – Clarence

+0

對不起,我固定的代碼現在 – odiszapc

+0

雅公司工作,我需要..感謝了很多花花公子.. – Clarence

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); 
    }