I have some European Charactacter in mySQL database table. My JSON code returns null object for those. I have also defined the header and utf8 encode still the result is null. I have attached my code snippets here
Header:
header("Content-Type: text/javascript; charset=utf-8");
JSON encoding
while ( $aRow = mysql_fetch_array( $rResult ) )
{
$row = array();
for ( $i=0 ; $i<count($aColumns) ; $i++ )
{
if ( $aColumns[$i] == "version" )
{
/* Special output formatting for 'version' column */
$row[] = ($aRow[ $aColumns[$i] ]=="0") ? '-' : $aRow[ $aColumns[$i] ];
}
else if ( $aColumns[$i] != ' ' )
{
/* General output */
$row[] = $aRow[ $aColumns[$i] ];
}
}
$output['aaData'][] = $row;
}
echo utf8_encode(json_encode( $output ));
JSON results in the firebug:
{"sEcho":1,"iTotalRecords":"190458","iTotalDisplayRecords":"4","aaData":[["University of Toronto ","Canada","72","17","41","144","7","16","6"],["The University of British Columbia ","Canada","71","22","44","176","11","16","7"],["University of Calgary","Canada","65","31","45","145","11","15","6"],[null,"Canada","63","18","45","125","12","26","6"]]}
Here in the JSON result one field is null in the name of University since the name of the university is in European characters.