php json 不能解析中文字符串???
今天遇到一个很奇怪的问题,在使用json_decode的时候,遇到一个奇怪的问题,在遇到中文字符组的时候,怎么都解析不了,把这个中文的字段删除,里面就能解析了....搞了半天不知道哪里的问题,路过的大虾帮忙看看
$nodeary=array();
while($row=mssql_fetch_array($rs)){
$description=strstr(//,,$row['description']);
array_push($nodeary,'{fchritemid:'.$row[fchritemid].',fchritemtypeid:'.$row[fchritemtypeid].',fchritemname:'.$row[fchritemname].',flotquoteprice:'.$row[flotquoteprice].',description:'.trim($description).',fdtmlastmodifytime:'.$row[fdtmlastmodifytime].',sales_volume:'.$row[sales_volume].'}');
}
$tbstr=implode(',',$nodeary);
?>{table:[]}
这里的description 字段有中文,只要把这个字段去掉就可以了,
header(content-type:text/html; charset=utf-8);
$ch = curl_init();
curl_setopt($ch, curlopt_url, $remoteapibasepath . sync2shop_api/item.php);
curl_setopt($ch, curlopt_returntransfer, 1);
curl_setopt($ch, curlopt_header, 0);
$output = curl_exec($ch);
curl_close($ch);
$obj=json_decode(iconv(gb2312,utf-8,$output));
var_dump( $obj);
//$obj=json_decode($output);
$rscount=count($obj->table);
$han=fopen(debug.php,a);
fwrite($han,$output.---------.$rscount);
fclose($han);
我是这么解析的,不知道哪里有错误,有谁帮忙看看!
分享到:
------解决方案--------------------
只能说你拿到的 json 不合规范,中文应该都是 \uxxxx 形式
------解决方案--------------------
你最好贴出你的数据,只要格式正确。不会有问题的
$s = '{a:我的,b:数据,c:[是从远程数据库,取的],d:难道会有影响吗?}';
$s = iconv('gbk', 'utf-8', $s);
print_r(json_decode($s));
stdclass object
(
[a] => 我的
[b] => 数据
[c] => array
(
[0] => 是从远程数据库
[1] => 取的
)