Recently, I decided to experiment with JSON and utilized json_encode to generate a JSON object structured as shown below:
[{
"timestamp": "12\/16\/2013 0:00",
"curr_property": "7211",
"curr_property_cost": "123",
"day_property": "48",
"day_property_cost": "281",
"curr_solar_generating": "4958",
"curr_solar_export": "0",
"day_solar_generated": "33",
"day_solar_export": "0",
"curr_chan1": "1964",
"curr_chan2": "4958",
"curr_chan3": "289",
"day_chan1": "13",
"day_chan2": "33",
"day_chan3": "1"
}, {
"timestamp": "12\/16\/2013 0:00",
"curr_property": "7179",
"curr_property_cost": "123",
"day_property": "72",
"day_property_cost": "281",
"curr_solar_generating": "4926",
"curr_solar_export": "0",
"day_solar_generated": "49",
"day_solar_export": "0",
"curr_chan1": "1980",
"curr_chan2": "4926",
"curr_chan3": "273",
"day_chan1": "19",
"day_chan2": "49",
"day_chan3": "2"
}]
Attempting to extract data from this JSON using the following script:
$(document).ready(
function() {
var jsonData = JSON.parse("<?php echo $jsondata; ?>");
console.log(jsonData.timestamp[0]);
});
I seem to be encountering an issue in parsing the JSON data correctly. Additionally, it's worth noting that by default, an array has a length of 0 in JavaScript. How can I retrieve the desired value in such cases? For reference, when performing a var_dump on $jsondata, the data output seems accurate.