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

标签 javascript php arrays parsing object

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

相关文章:

javascript - 使用空主体 for-in 循环将对象属性复制到数组

mysql - 如何在 MySQL 的 JSON 路径中使用 CONCAT?

javascript - 尝试本地数据存储时键入错误,如何启动我的网站?

javascript - 在 watch 破坏测试中使用 Jasmine 形式有效性进行 AngularJS 单元测试

javascript - DOM 替换元素上的整个样式属性 (CSSStyleDeclaration)

php - 错误 mysqlconnect() max_users_connection

c++ - 'new' 在 C++ 中是如何动态的

javascript - 从字符串中生成 <br/> 在 react 中起作用

c# - Webservice 需要 Byte[] - 我如何从 PHP 发送它?

php - 如何对多个数组进行 m​​ysql UPDATE