Home  >  Article  >  Backend Development  >  php数组输出这样的json,该如何处理

php数组输出这样的json,该如何处理

WBOY
WBOYOriginal
2016-06-13 12:04:501024browse

php数组输出这样的json
请问如何输出这样的json ?



{
    data = (
                {
"article_url" = "/disease/item/1";
"create_time" = "2014-08-11 11:38:58";
"knowledge_id" = 1;
title = "\U6d4b\U8bd5\U9057\U4f20\U75c5\U5e931";
},
                {
"article_url" = "/disease/item/3";
"create_time" = "2014-07-22 15:38:28";
"knowledge_id" = 3;
title = "\U6211\U7684\U9057\U4f20\U77e5\U8bc6";
 }
);
    errcode = 0;
    errdesc = "";
}

其中 ,来源于表的数据
"article_url" = "/disease/item/1";
"create_time" = "2014-08-11 11:38:58";
"knowledge_id" = 1;
title = "\U6d4b\U8bd5\U9057\U4f20\U75c5\U5e931";

表的循环读取程序,

      $i=0;
$listarr=array();
while($db->ROW())
{
$listarr[$i]["article_url"]=$ROW[article_url];
$listarr[$i]["create_time"]=$ROW[create_time];
$listarr[$i]["knowledge_id"]=$ROW[knowledge_id];
$listarr[$i]["titlee"]=$ROW[title];
$i++;

}
如何通过这段 while程序输出最上面的json ?
请大家帮看看。
------解决方案--------------------
如果不需要格式話,可以
echo jsonFormat($result);
改為
echo json_encode($result);
即可。

上面的function都可以不用了。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn