将Json数组转换为字符串

时间:2013-09-05 16:55:28

标签: php json

我的结果是json数组格式,我想将我的数组结果更改为json字符串格式。我该怎么做呢。请帮助..我不知道我怎么做这个:(。新到json 我作为json数组的结果是这样的

[[ “Date.UTC(2011,09,03)”, “1”],[ “Date.UTC(2011,09,06)”, “53”],[“Date.UTC(2011年, 09,07)”, “178”],[ “Date.UTC(2011,09,08)”, “305”],[ “Date.UTC(2011,09,09)”, “152”],[ “Date.UTC(2011,09,11)”, “20”],[ “Date.UTC(2011,09,12)”, “239”],[ “Date.UTC(2011,09,13)” , “25”],[ “Date.UTC(2011,09,14)”, “316”],[ “Date.UTC(2011,09,15)”, “169”],[“Date.UTC( 2011,09,16)”, “20”],[ “Date.UTC(2011,09,19)”, “126”]

我的代码

   $mysql_connect = mysql_connect($db_host, $db_user, $db_pword, $db_name);
    $query = "Select DATE_FORMAT(`timestamp`,'%Y,%m,%d') as date, Count(*) as frequency               from mytable group by date_format(`timestamp`,'%Y,%m,%d')";
   if (!$mysql_connect)  die("unable to connect to database: " . mysql_error());

  @mysql_select_db($db_name) or die( "Unable to select database");

 $result = mysql_query($query);
 $response = array();
 if($result === FALSE)
{
   die(mysql_error()); // TODO: better error handling
}
while($row=mysql_fetch_array($result))
       {  


    $date = "Date.UTC(".$row ['date'].")";
    $frequency =$row['frequency'];
    $response[] = array ($date,$frequency);


     }

 JSONArray jArray;
  String s = jArray.toString(); 

     mysql_close($mysql_connect);

1 个答案:

答案 0 :(得分:1)

json_encode

<?php
$json_string = json_encode($your_array);

你有没有打扰过Google吗?