I have created the following function
var jsonData = <?php echo $jsondata; ?>;
var objectLength = <?php echo $lines; ?>; /*length of the object*/
var dataArray = [];
var objectParser = {};
objectParser.getArrays = function(jsonData, dataType) {
var i = 0;
stringName = dataType;
for (i = 0; i<=objectLength; i++) {
dataArray.push(jsonData[i].stringName);
}
return dataArray;
}
var timeStamp = objectParser.getArrays(jsonData,'timestamp');
console.log(timeStamp);
to take in JSON data and read the data from it. My problem is that right now I am getting a
Uncaught TypeError: Cannot read property 'stringName' of undefined
in the code which I am not sure why it's happening. Doing
console.log(jsonData[0].timestamp) works just fine
Here is the json data sample [{
"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"
}, ..........]