2013-12-20 55 views
0

下面是我的代碼,並返回我JSON數組,但我需要從響應刪除括號需要刪除squre支架json_encode(陣列())

$sql = "select user_loginId,user_password from wnl_user where user_loginId='student01' and user_password='123456' and user_status='active'"; 
      //echo $sql;die; 
      $result = mysql_query($sql); 

      $num_rows = mysql_num_rows($result); //function to get number of rows from result 

       $posts = array(); 

       if($num_rows != 0) 
       { 
        if(mysql_num_rows($result)) { 
        while($post = mysql_fetch_assoc($result)) { 
         $posts[] = array('status'=>'1','post'=>$post); 
        } 
        } 

        echo json_encode(array('posts'=>$posts)); 
       } 
       else 
       { 
        echo json_encode(array('status'=>"0",'data'=>"No Data Found")); 
       } 

和應對

{"posts":[{"status":"1","post":{"user_loginId":"student01","user_password":"123456"}}]} 

我需要刪除{「帖子」:[這從起始方括號和]}也從最後。

請幫我從這個問題

+0

呃...'回聲json_encode($個);' – cmorrissey

回答

3

使用,您可以刪除array('posts'

echo json_encode($posts); 

,而不是

echo json_encode(array('posts'=>$posts));