下面是我的代码,它返回我的json数组,但我需要从响应中删除方括号
$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 :(得分:3)
使用,您可以删除array('posts'
echo json_encode($posts);
而不是
echo json_encode(array('posts'=>$posts));