0

我需要制作生成这样的 json 数据的示例 php 代码:

?(/* AAPL historical OHLC data from the Google Finance API */
[
/* Apr 2006 */
[1145404800000,65.65],
[1145491200000,67.63],
[1145577600000,67.04],
[1145836800000,65.75],
[1145923200000,66.17],
[1146009600000,68.15],
[1146096000000,69.36],
[1146182400000,70.39],
/* May 2006 */
[1146441600000,69.60],
[1146528000000,71.62],
[1146614400000,71.14],
[1146700800000,71.13],
[1146787200000,71.89],
[1147046400000,71.89],
[1147132800000,71.03],
[1147219200000,70.60],
[1147305600000,68.15],
[1147392000000,67.70],
[1147651200000,67.79],
[1147737600000,64.98],
[1147824000000,65.26],
[1147910400000,63.18],
[1147996800000,64.51],
[1148256000000,63.38],
[1148342400000,63.15],
[1148428800000,63.34],
[1148515200000,64.33],
[1148601600000,63.55],
[1148947200000,61.22],
[1149033600000,59.77],
/* Apr 2013 */
[1364774400000,428.91],
[1364860800000,429.79],
[1364947200000,431.99],
[1365033600000,427.72],
[1365120000000,423.20],
[1365379200000,426.21],
[1365465600000,426.98],
[1365552000000,435.69],
[1365638400000,434.33],
[1365724800000,429.80],
[1365984000000,419.85],
[1366070400000,426.24]
]);

*编辑

像这样的数据:http ://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback= ?

但没有将外部 json 脚本加载到 php 脚本中。只需在一个脚本 php 中生成 json 数据。我怎么能做一个这样的?

4

2 回答 2

6

使用数据创建一个多维数组:

$data=array(
array(1145404800000,65.65),
array(1145491200000,67.63),
array(1145577600000,67.04),
array(1145836800000,65.75),
array(1145923200000,66.17),
//...
);

使用 json_encode 将其转换为 json 字符串:

echo json_encode($data);
于 2013-04-18T20:46:30.383 回答
2

根据需要生成数据数组,并将其传递到json_encode.

于 2013-04-18T20:42:59.240 回答