• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php json 不能解析中文字符串?解决方法

php 搞代码 3年前 (2022-01-24) 14次浏览 已收录 0个评论

php json 不能解析中文字符串???
今天遇到一个很奇怪的问题,在使用json_decode的时候,遇到一个奇怪的问题,在遇到中文字符组的时候,怎么都解析不了,把这个中文的字段删除,里面就能解析了….搞了半天不知道哪里的问题,路过的大虾帮忙看看

	$nodeAry=array();<br />	while($row=mssql_fetch_array($rs)){<br />		$description=strstr("//","",$row['description']);<br />	   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"].'"}');<br />    }<br />	$tbstr=implode(',',$nodeAry);   <br /><br />?>{"table":[<?=$tbstr;?>]}

这里的description 字段有中文,只要把这个字段去掉就可以了,

 header("Content-Type:text/html; charset=utf-8");<br />	<br />	$ch = curl_init();<br />	curl_setopt($ch, CURLOPT_URL, $remoteAPIBasePath . "sync2shop_api/item.php");<br />	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<br />	curl_setopt($ch, CURLOPT_HEADER, 0);<br />	$output = curl_exec($ch);<br />	<br />	curl_close($ch);<br />	<br />	$obj=json_decode(iconv("gb2312","utf-8",$output));<br />	var_dump( $obj);<br />	//$obj=json_decode($output);<br /><br />	$rscount=count($obj->table);<br />	<br />	$han=fopen("debug.php","a");<br />	fwrite($han,$output."---------".$rscount);<br />	fclose($han);

我是这么解析的,不知道哪里有错误,有谁帮忙看看!

发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址