I had similar issie with this. This may not be the best code but it work for me. Maybe it can help you.
Try this (I am using codeigniter):
function getData() {
$data = $this->Teplomer_model->showData(); //get your data from database as return $query->result();
//create array
$arr = array();
//foreach data to array
foreach ($data as $row) {
$arr[] = array(
"id" => $row->id_teplota,
"datum" => $row->cas_teplota,
"teplota" => $row->teplota_teplota,
"vlhkost" => $row->vlhkost_teplota
);
}
//echo array as json and check if there is any numbers
echo json_encode($arr, JSON_NUMERIC_CHECK );
}
And output:
{"id":3,"datum":"2019-02-08 14:03:31","teplota":22.33,"vlhkost":19.7},{"id":4,"datum":"2019-02-08 14:18:35","teplota":23,"vlhkost":19}