What can you do if json_encode doesn’t work

You want to generate a json code but the function json_encode doesn't work? To solve this problem, you must only encode all string data.

Example:


$jsonval = array();
while($get = mysqli_fetch_assoc($mn)):
$json = array();
$json["name"] = utf8_encode($get["name"]);
$json["age"] = utf8_encode($get["age"]);
array_push($jsonval,$json);
endwhile;
echo json_encode($jsonval);

So, if the function json_encode doesn't work, add utf8_encode to all string data!









Leave a Comment