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
)