php - Prevent strtotime being encoded as string by json_encode -
i building data status dashboard uses highcharts.js, , loading ajax, when using json_encode timestamps getting quoted, means highcharts chokes on them.
the code is:
$responsedata = array(); foreach ($monitors $monitor => $data) { foreach (array_reverse($data['responsetime']) $responsetime) : $responses[] = array(strtotime($responsetime['datetime'])*1000 => $responsetime["value"]); endforeach; $responsedata[] = array('name' => $data['friendlyname'], 'data' => $responses); } $responsedata = json_encode($responsedata,json_numeric_check); using json_numeric_check prevents problems value, key (a timestamp) gets quoted still.
example output:
[{"name":"series 1","data":[{"1432933860":1622},{"1432935660":1458},{"1432937461":1388}]},{"name":"series 2","data":[{"1432933860":1622},{"1432935660":1458},{"1432937461":1388}]}] desired output:
[{"name":"series 1","data":[{1432933860:1622},{1432935660:1458},{1432937461:1388}]},{"name":"series 2","data":[{1432933860:1622},{1432935660:1458},{1432937461:1388}]}] what doing wrong? keys quoted perhaps?? way around this?
from objects
an object structure represented pair of curly brackets surrounding 0 or more name/value pairs (or members). name string.
and strings
a string begins , ends quotation marks.
so according standard: yes, should quote key. maby try escape key in javascript? store them in value , remove non-numeric characters?
something like:
myjsonkey = myjsonkey.replace(/\d/g,'');
Comments
Post a Comment