繁体   English   中英

用php解析Javascript数组或对象

[英]parsing Javascript array or object with php

我有一个页面可以像这样响应javascript,并且我想用php解析“系列”数组

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM