I'm getting a query result with JSON but with special characters, It's showing NULL instead of the correct result. I've tried array_map('utf8_encode') but I'm still getting the same error.

The code:

if (mysql_num_rows($result) > 0) {
    // looping through all results
    // products node
   $response["reserves"] = array();

    while ($row = mysql_fetch_array($result)) {
        // temp user array
        $product = array();
        array_map('utf8_encode', $product);
        $product["id_reserve"] = $row["id_r"];
        $product["description"] = $row["d_reserve"];
        // push single product into final response array
        array_push($response["reserves"], $product);
    // success
    $response["success"] = 1;

    // echoing JSON response
    echo json_encode($response);
Question author User1423168 | Source



(Posted on behalf of the OP).

To set the array value utf-8 the function utf8_encode has to be put before the $row. The result is:

$product["description"] = utf8_encode($row["d_reserve"]);
Answer author

Ask about this question here!