我有一个像这样响应 javascript 的页面,我想用 php 解析“series”数组
$(function () {
$('#container').highcharts({
series: [{
name: 'IP',
data: [3.09,3.24,3.33,]
}, {
name: 'IPK',
data: [3.09,3.16,3.22,]
}]
});
});
最有效的方法是什么?
最佳答案
在 php 中你有 json_decode解析 JSON 数据
var_dump(json_decode($series, true));
例如
var output = {series: [{
name: 'IP',
data: [3.09,3.24,3.33,]
}, {
name: 'IPK',
data: [3.09,3.16,3.22,]
}];
// Send output of JSON.stringify(output) to php via POST, GET or XHR.
在 PHP 中:
$input = json_decode($_GET['input'], true);
// $input = array('output' =>
array('series' =>
array(
'name' => 'IP',
'data' => array(3.09, 3.24, 3.33)
),
array(
'name' => 'IPK',
'data' => array(3.09, 3.16, 3.22)
)
)
);
关于javascript - 使用 php 解析 Javascript 数组或对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54880848/