The Chinese character is NULL when the json Array is transformed. Solution-php Tutorial

Source: Internet
Author: User
Tags php json
Chinese is NULL when arrays are converted in json format. & lt ;? Php $ json [{ZtdID: 100000, ZtdNo: 001 & nbsp;, ZtdName: Shop 1 & nbsp;, Address: Shop No. 01, YY Road, ZZ district, XX city & nbsp ;, remark:, AreaID: 01, ZtdTel: 0000-8888888. the Chinese character is NULL when the json Array is converted. Solution
$ Json = '[{"ZtdID": "100000", "ZtdNo": "001", "ZtdName": "Shop 1", "Address ": "Shop No. 01, YY Road, ZZ district, XX city", "Remark": "", "AreaID": "01", "ZtdTel": "0000-8888888 ", "ZtdContact": "Zhangsan" },{ "ZtdID": "100001", "ZtdNo": "002", "ZtdName": "Shop 1", "Address ": "Shop No. 01, YY Road, ZZ district, XX city", "Remark": "", "AreaID": "01", "ZtdTel": "0000-8888888 ", "ZtdContact": "Li San"}] ';
Var_dump (json_decode ($ json, true ));

?>
The output is NULL.
After careful consideration, it is a coding problem. how can this problem be solved?


------ Solution --------------------
Iconv ('gbk', 'utf-8', 'convert Chinese to json ');

PHP json does not support the gbk gb2312 format.

------ Solution --------------------

$ Json = '[{"ZtdID": "100000", "ZtdNo": "001", "ZtdName": "Shop 1", "Address ": "Shop No. 01, YY Road, ZZ district, XX city", "Remark": "", "AreaID": "01", "ZtdTel": "0000-8888888 ", "ZtdContact": "Zhangsan" },{ "ZtdID": "100001", "ZtdNo": "002", "ZtdName": "Shop 1", "Address ": "Shop No. 01, YY Road, ZZ district, XX city", "Remark": "", "AreaID": "01", "ZtdTel": "0000-8888888 ", "ZtdContact": "Li San"}] ';
Debug ($ json );
Debug (json_decode ($ json, true ));

------------------ The output is normal.

[{"ZtdID": "100000", "ZtdNo": "001", "ZtdName": "Shop 1", "Address ": "Shop No. 01, YY Road, ZZ district, XX city", "Remark": "", "AreaID": "01", "ZtdTel": "0000-8888888 ", "ZtdContact": "Zhangsan" },{ "ZtdID": "100001", "ZtdNo": "002", "ZtdName": "Shop 1", "Address ": "Shop No. 01, YY Road, ZZ district, XX city", "Remark": "", "AreaID": "01", "ZtdTel": "0000-8888888 ", "ZtdContact": "Li San"}]

Array
(
[0] => Array
(
[ZtdID] = & gt; 100000
[ZtdNo] => 001
[ZtdName] => Store 1
[Address] => shop 01, YY Road, ZZ district, XX city
[Remark] =>
[AreaID] => 01
[ZtdTel] = & gt; 0000-8888888
[ZtdContact] => John
)

[1] => Array
(
[ZtdID] = & gt; 100001
[ZtdNo] => 002
[ZtdName] => Store 1
[Address] => shop 01, YY Road, ZZ district, XX city
[Remark] =>
[AreaID] => 01
[ZtdTel] = & gt; 0000-8888888
[ZtdContact] => San Li
)

)

------ Solution --------------------
$ Json = '{"ZtdID": "100000", "ZtdNo": "001", "ZtdName": "Shop 1", "Address ": "Shop No. 01, YY Road, ZZ district, XX city", "Remark": "", "AreaID": "01", "ZtdTel": "0000-8888888 ", "ZtdContact": "James "}';

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.