{ "label": "Devices per year", "data": [ [1999, 3.0], [2000, 3.9], [2001, 2.0], [2002, 1.2], [2003, 1.3], [2004, 2.5], [2005, 2.0], [2006, 3.1], [2007, 2.9], [2008, 0.9] ] }
经过几次尝试,我没有找到解决方案。例如,我尝试了这个:
$arrayDateAndMachine = array( "1999"=>3.0, "2000"=>3.9 ); $arr = array( "label" => "Devices per year", "data" => $arrayDateAndMachine ); var_dump(json_encode($arr));
$obj = new stdClass(); $obj->label="Devices per year"; $obj->data = array( array('1999','3.0'), array('2000','3.9'), //and so on... ); echo json_encode($obj);