需要卸下支架squre json_en code(阵列()) [英] Need to remove squre bracket json_encode(array())
本文介绍了需要卸下支架squre json_en code(阵列())的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我的code,并返回我json的数组,但我需要从响应删除括号
Below is my code and it return me json array but i need to remove square bracket from response
$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"}}]}
我需要删除的 {上岗:这从起始方括号和]} 也结束
i need to remove {"posts":[ this from the starting square bracket and ]} also from the end.
请帮我从这个问题
推荐答案
使用,您可以删除阵列(帖子
echo json_encode($posts);
而不是
echo json_encode(array('posts'=>$posts));
这篇关于需要卸下支架squre json_en code(阵列())的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文