我的結果是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);
你一定是在開玩笑。 https://www.google.com/search?q=php+parse+json –
你在尋找php [json_encode](http://php.net/manual/en/function.json-encode.php) – bansi