从sql查询出来的Json无法提供预期的输出

时间:2017-07-05 16:13:04

标签: sql-server json highcharts

data.php文件:

$sql = "SELECT [name],[Prev Year],[PY_mkr_col],[PY_sg_col] FROM 
dbo.s5_test";

$result = sqlsrv_query($con, $sql);;

$category = array(); $category['name'] = 'month'; 
$series1 = array(); 
$series1['name'] = 'Prev Year';
$series1['color'] = 'PY_mkr_col';
$series1['segmentColor'] = 'PY_sg_col';

while($r = sqlsrv_fetch_array($result)) 
{ 
    $category['data'][] = $r['name']; 
    $series1['data'][] = $r['Prev Year']; 
} 

$result = array(); 
array_push($result,$category); 
array_push($result,$series1);
print json_encode($result, JSON_NUMERIC_CHECK); 
sqlsrv_close($con);
?>

输出Json:

[{"name":"month","data":
["Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","Jan","Feb","Mar"]},
{"name":"Prev Year","color":"PY_mkr_col","segmentColor":"PY_sg_col","data":
[140,154,138,173,144,148,168,130,143,137,171,125]}]

预期产出:

PY_mkr_col和PY_sg_col应包含以下值

PY_mkr_col:

   ['rba(128,128,128,0)', green, 
    'blue','rba(128,128,128,0)', green, 'blue','rba(128,128,128,0)', green, 
    'blue','rba(128,128,128,0)', green, 'blue']

PY_sg_col:

 [#FF0000, #008000,#FF0000, #008000,#FF0000,  
      #008000,#FF0000, #008000,#FF0000, #008000,#FF0000, #008000]<br>

在SQL表中,值&#39; rba(128,128,128,0)&#39;,&#39;绿色&#39;和#FF0000的格式为nvarchar(40)。

此Json输出将作为带有Multi_color.js库的高位图中的Series []传递。

0 个答案:

没有答案