json problem {"data":Malformed UTF-8 characters, possibly incorrectly encoded

json problem {"data":Malformed UTF-8 characters, possibly incorrectly encoded

SwordmSwordm Posts: 9Questions: 4Answers: 0

Hello, I purchased editor ,
during trial everything were normal but today I receive tis error ;

Malformed UTF-8 characters, possibly incorrectly encoded.

this is my code

$('#example').DataTable( {
        dom: 'B<"clear">lfrtip',
        ajax: "data/sod.php",
        columns: [

on sod.php I have a query printing results as json..

echo '{"data":';
    $rows = array();
    $result = odbc_exec($conn, $query);
    
    
    while($r=odbc_fetch_array($result))
    {
    
        $rows[] = $r;
            
    }

                    print json_encode($rows);
                echo json_last_error_msg();
                echo ',
  "options": [],
  "files": [],
  "draw": 1
}';

Answers

  • allanallan Posts: 63,468Questions: 1Answers: 10,466 Site admin

    Hi,

    What database are you using? Is it set to be utf8 itself?

    Thanks,
    Allan

  • SwordmSwordm Posts: 9Questions: 4Answers: 0

    I am using DB2 database, I read from DB2 write to mysql,

    first line solved my problem, second and third line can be an option but this time change all values on query.

        while($r=odbc_fetch_array($result))
        {
    $r = str_replace  ("'", "", $r );
    $r = preg_replace('/[\x00-\x1F\x7F]/', '', $r);
    $r  = preg_replace ('/[^\p{L}\p{N}]/u', '', $r );
    
    

    it is better doing this in query but i could not.

    this is the query line of error, i have added if null

    IFNULL(CAST(CAST(TURKEY_SOD.SYVR01 as CHAR(40) FOR BIT DATA) as CHAR(40) CCSID 1026),0) AS ONOTES,

  • allanallan Posts: 63,468Questions: 1Answers: 10,466 Site admin

    I fear that this is out of the scope of DataTables support. You'd probably need to ask on StackOverflow or a PHP forum. It sounds like the data being read from the database is either not utf8 encoded, or it has invalid utf8 characters in it.

    Allan

This discussion has been closed.