bhensfs 发表于 2014-4-17 13:30:26

关于sql查询问题,请大神进来看下,谢谢!

$sql= "select distinct cs_brand_name from tb_cars where cs_brand_initials = 'A' or cs_brand_name like'%奥%' ";
                  echo $sql;
          $query=$this->db->query($sql);
                  $result= $query->result();
                   return $result;


echo json_encode($result);

这是我自定义查询语句返回的值



[{"cs_brand_name":"\u5965\u8fea"},{"cs_brand_name":"\u5965\u514b\u65af"},{"cs_brand_name":"\u963f\u5c14\u6cd5\u00b7\u7f57\u7c73\u6b27"},{"cs_brand_name":"\u963f\u65af\u987f\u00b7\u9a6c\u4e01"},{"cs_brand_name":"AC Schnitzer"}]

怎么成编码了?

ljc 发表于 2014-4-17 14:03:06

json_encode了 是转成json了,就是unicode编码了。。。

bhensfs 发表于 2014-4-17 15:11:18

ljc 发表于 2014-4-17 14:03
json_encode了 是转成json了,就是unicode编码了。。。

查了下资料,才知道JSON不能转汉字,怎么整呢?

ljc 发表于 2014-4-17 16:48:18

json_decode(),就能转成原有的数组了

小刘 发表于 2014-4-18 15:40:32

PHP里
json_decode($result), 就好了

js里   用的是jquery
$.post(url,data,function(msg){
//js直接循环json
$(msg).each(function(i,item){
document.write(item.cs_brand_name);

});


},'json')
页: [1]
查看完整版本: 关于sql查询问题,请大神进来看下,谢谢!