PHP JSON cannot parse Chinese string???
Today encountered a very strange problem, in the use of Json_decode, encountered a strange problem, in the face of the Chinese character group, how can not parse, the field to delete, the inside can parse .... Do not know where the problem, a passing prawn help to see
$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": [
]}
The Description field here is in Chinese, just 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 so analytic, do not know where there are errors, who help to see!
Share to:
------Solution--------------------
Can only say that you get the JSON is not standardized, Chinese should be \uxxxx form
------Solution--------------------
You'd better post your data as long as the format is correct. It won't be a problem.
$s = ' {"A": "My", "B": "Data", "C": ["is from remote database", "Fetch"], "D": "Does it have an impact?" "}';
$s = iconv (' GBK ', ' utf-8 ', $s);
Print_r (Json_decode ($s));
StdClass Object
(
[A] =-my
[B] = data
[c] = = Array
(
[0] = = from the remote database
[1] = = Fetch of
)