php - 我如何在 php 脚本中制作这样的示例 json?

标签 php javascript jquery ajax json

我需要制作生成 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 数据即可。我怎样才能做出这样的一个?

最佳答案

使用数据创建多维数组:

$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);

关于php - 我如何在 php 脚本中制作这样的示例 json?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16092645/

相关文章:

javascript - 将连续(上传)的内容放在多个页面(div)中

javascript - 如何将多个选中的数据及其各自的 ID 提取到数组中 - jQuery

php - 从日期到日期 - 搜索和显示

php - Ratchet 服务器与长轮询

php - 在mysql中搜索字符串数组

javascript - 为什么当我尝试对列表进行排序时单击按钮时 list.js 不起作用

javascript - document.body.removeEventListener 移除所有点击事件监听器(不是指定函数)为什么?

jquery - 无法获得 <label> 元素的正确宽度或outerWidth

php - API 在 WordPress 中上传文件

php - Laravel Google Auth 使用 artdarek/oauth-4-laravel