I have an unusual situation where depending on the value of active being 0 or 1 causing invalid JSON to be interpreted client side. How can I change value active from an int to string within the array so that json_encode is valid? Or is it something else entirely? Looking at both json outputs look identical...
Active and ID are both integers. Everything else is a string.
Interestingly enough, if active is 1 instead of 0 the JSON is valid and displays properly.
JSON:
[
{
"id": 254,
"name": "Test",
"company": "Test",
"email": "Test",
"phone": "Test",
"comments": "Test",
"ticket": "Test",
"assigned": "",
"active": 0,
"date_created": "2018-12-02 00:56:49"
}
]
Code:
$stmt = $conn->prepare("SELECT id, name, company, email, phone, comments, ticket, assigned, active, date_created FROM tickets_info");
$stmt->execute();
$result = $stmt->get_result();
$result_array = array();
while ($row = $result->fetch_assoc()) {
array_push($result_array, $row);
}
header("Content-Type: application/json");
echo json_encode($result_array);