Php json cannot parse Chinese strings? Solution

Source: Internet
Author: User
Phpjson cannot parse Chinese Strings ??? Today I encountered a very strange problem. when I was using json_decode, I encountered a strange problem. when I encountered a Chinese character Group, I couldn't parse it and deleted the Chinese field, it will be resolved .... I don't know where the problem occurs for a long time. let's take a look at $ nodeAryarray (); while ($ rowmssql_fetch_array ($ php json cannot parse Chinese Strings ???
Today I encountered a very strange problem. when I was using json_decode, I encountered a strange problem. when I encountered a Chinese character Group, I couldn't parse it and deleted the Chinese field, it will be resolved .... I don't know where the problem occurs for a long time. let's take a look at the passing prawns.

$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":[ ]}


Here, the description field contains Chinese characters. you only need to remove this field,

 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);


I am parsing it like this and I don't know where the error is. who can help me!

Share:


------ Solution --------------------
It can only be said that the json you get is not standard, and the Chinese format should be \ uxxxx
------ Solution --------------------
You 'd better paste your data as long as the format is correct. No problem
$ S = '{"a": "My", "B": "Data", "c": ["from remote database", "retrieved"], "d": "Is there any impact? "}';
$ S = iconv ('gbk', 'utf-8', $ s );
Print_r (json_decode ($ s ));
StdClass Object
(
[A] => My
[B] => Data
[C] => Array
(
[0] => yes from the remote database
[1] => Retrieved
)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.