Home Backend Development PHP Tutorial php json 不能解析中文字符串?解决方法

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

Jun 13, 2016 pm 12:38 PM
curl json nbsp

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;?>]}
Copy after login


这里的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);
Copy after login


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

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

10 Ways to Adjust Brightness on Windows 11 10 Ways to Adjust Brightness on Windows 11 Dec 18, 2023 pm 02:21 PM

10 Ways to Adjust Brightness on Windows 11

How to turn off private browsing authentication for iPhone in Safari? How to turn off private browsing authentication for iPhone in Safari? Nov 29, 2023 pm 11:21 PM

How to turn off private browsing authentication for iPhone in Safari?

Tutorial on updating curl version under Linux! Tutorial on updating curl version under Linux! Mar 07, 2024 am 08:30 AM

Tutorial on updating curl version under Linux!

Win10/11 digital activation script MAS version 2.2 re-supports digital activation Win10/11 digital activation script MAS version 2.2 re-supports digital activation Oct 16, 2023 am 08:13 AM

Win10/11 digital activation script MAS version 2.2 re-supports digital activation

What is the difference between MySQL5.7 and MySQL8.0? What is the difference between MySQL5.7 and MySQL8.0? Feb 19, 2024 am 11:21 AM

What is the difference between MySQL5.7 and MySQL8.0?

Combination of golang WebSocket and JSON: realizing data transmission and parsing Combination of golang WebSocket and JSON: realizing data transmission and parsing Dec 17, 2023 pm 03:06 PM

Combination of golang WebSocket and JSON: realizing data transmission and parsing

Performance optimization tips for converting PHP arrays to JSON Performance optimization tips for converting PHP arrays to JSON May 04, 2024 pm 06:15 PM

Performance optimization tips for converting PHP arrays to JSON

Use the json.MarshalIndent function in golang to convert the structure into a formatted JSON string Use the json.MarshalIndent function in golang to convert the structure into a formatted JSON string Nov 18, 2023 pm 01:59 PM

Use the json.MarshalIndent function in golang to convert the structure into a formatted JSON string

See all articles