我很困惑寫這篇文章,我該如何實現這個類似的輸出。我很早就開始使用json編碼。但是這對我來說是不同的。PHP:編碼嵌套的JSON數組問題
[{
type: 'pie',
name: 'Browser share',
innerSize: '40%',
data: [
['Firefox', 10.38],
['IE', 56.33],
['Chrome', 24.03],
['Safari', 4.77],
['Opera', 0.91],
{//over here i can't get this braces
name: 'Proprietary or Undetectable',
y: 0.2,
dataLabels: {
enabled: false
}
}
]
}]
這裏是我的代碼,
$percentage = array();
$arr2 = new stdClass();
$arr2->type = 'pie';
$arr2->name = 'Browser share';
$arr2->innerSize = '40%';
while($azSoc = mysql_fetch_assoc($az)){
$arr2->data[] = array("".$azSoc['criteria_name']."", $azSoc['crit_score_percentage']);
}
$arr2->name = 'Porperty ok';
$arr2->y = 0.2;
$arr2->dataLabels[] = array('enable',false);
array_push($percentage, $arr2);
echo json_encode($percentage);
我的代碼輸出給我,
[{"type":"pie","name":"Porperty ok","innerSize":"40%","data":[["tes","25"],
["awdawdas","25"],["awdawd","25"],["ehhehe","25"]],"y":0.2,"dataLabels":
[["enable",false]]}]
什麼,你正在努力實現是無效的JSON。 – RiggsFolly
但是,如何,也許我錯了我的問題是它是一個數組?因爲我已經多次使用其他代碼。放入js並通過json.parse重寫爲我工作 –