gpt4 book ai didi

javascript - 使用 php 解析 Javascript 数组或对象

转载 作者:行者123 更新时间:2023-12-03 00:07:53 26 4
gpt4 key购买 nike

我有一个像这样响应 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com