Php JSON编码问题
这种编码方式有什么问题Php JSON编码问题,php,javascript,ajax,json,Php,Javascript,Ajax,Json,这种编码方式有什么问题 <?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
<?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");
?>
脚本输出:
{物品:1000件,数量:0件,捐赠:0件,总数:1000件}
我的json数组中存在parase错误。这个脚本的输出是什么?它输出:{items:1000,mitems:0,捐赠:0,total:1000}这是非常有效的json,在那里输出,看起来很好。要么你的解析器编码错误,要么你的客户端javascript错误。这是完全有效的json。