我想知道为什么json_encode回显“ null”,而我将西班牙语字符用作“ñ”

$link=mysql_connect("localhost","josilandia","*****");
mysql_select_db("critica",$link);
mysql_query("SET NAMES utf8");
$region="Mosel-Saar-Ruwer";

$resultado=mysql_query("SELECT marcavino,comentario,estrellas FROM recomendacion2
 WHERE region='$region'");

$recomendacion=array();
while ($row = mysql_fetch_assoc($resultado)) {
   $lamarcavino =utf8_decode($row['marcavino']);
   $elcomentario =utf8_decode($row['comentario']);

   $laestrella = $row['estrellas'];
   $arr=array('marcavino'=>"$lamarcavino",'comentario'=>"$elcomentario",'estrellas'=>"$laestrella");
     $recomendacion[]= $arr;

  print(json_encode($recomendacion));

最佳答案

$lamarcavinoutf8_decode()之后的ISO 8859-1,因为utf8_decode() converts from UTF-8 to ISO 8859-1

json_encode() does only support UTF-8和ISO 8859-1中的某些较高字符在UTF-8中无效。

09-07 09:22