I have a page that responds to javascript like this and I want to parse the 'series' array with php
$(function () {
$('#container').highcharts({
series: [{
name: 'IP',
data: [3.09,3.24,3.33,]
}, {
name: 'IPK',
data: [3.09,3.16,3.22,]
}]
});
});
what is the most effective method for doing that ?
1 Answer 1
In php you have json_decode to parse JSON data
var_dump(json_decode($series, true));
E.g.
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.
And in 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)
)
)
);
answered Feb 26, 2019 at 8:06
Xyz
6,0516 gold badges43 silver badges60 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Hmerman6006
I struggled hard and long for this answer and to understand this. Remember in JS use
JSON.stringify(obj) on json object together with json_decode($_GET['input'], true) in php. They are not mutually exclusive but form a simbiose parsing relationship of two different languages and habitats.Explore related questions
See similar questions with these tags.
default
JSON.stringify( data )->ajax->json_decode-> :-)