0
這種編碼方式有什麼問題?JSON編碼問題php
<?php
include ("../includes/db_con.php");
$itemResults = mysql_query("SELECT `sold_for` FROM `items` WHERE `item_did_sell`='1'") or die();
$mIResults = mysql_query("SELECT `mi_price`, `mi_total_sold` FROM `misc_items` WHERE `mi_total_sold`>'1'") or die();
$donationResults = mysql_query("SELECT `amount` FROM `donations`") or die(mysql_error());
$total = 0;
$itemTotal = 0;
$mITotal = 0;
$donationTotal = 0;
while($row = mysql_fetch_assoc($itemResults)){
$itemTotal += $row['sold_for'];
$total += $itemTotal;
}
while($row = mysql_fetch_assoc($mIResults)){
$mITotal += ($row['mi_price'] * $row['mi_total_sold']);
$total += $mITotal;
}
while($row = mysql_fetch_assoc($donationResults)){
$donationTotal += $row['amount'];
$total += $donationTotal;
}
header("Content-Type: application/json");
$arr = array('items' => $itemTotal,'mitems' => $mITotal,'donations' => $donationTotal,'total' => $total);
$arr = json_encode($arr);
echo $arr;
include ("../includes/db_discon.php");
?>
腳本輸出: {"items":1000,"mitems":0,"donations":0,"total":1000}
發生的我的客戶端的JavaScript(已認證)有在我的JSON陣列的parase錯誤。
此腳本的*輸出*是什麼? – deceze 2012-02-01 01:07:21
它輸出:'{「項目」:1000,「mitems」:0,「捐款」:0,「total」:1000}' – lampwins 2012-02-01 01:08:41
這是非常有效的JSON輸出那裏,看起來不錯。 – deceze 2012-02-01 01:09:26