Phpjson and array conversion and Chinese garbled characters

Source: Internet
Author: User
The PHPJSON application starts with PHP5.2. JSON support has been added since this version. There are two main functions: json_encode and json_decode.

Php json applications start with PHP5.2. JSON support has been added since this version. There are two main functions: json_encode and json_decode.

 

JSON is a data storage format, just like PHP serialized strings. It is a data description. For example, if we store an array after serialization, we can easily apply it after deserialization. The same is true for JSON. PHP5.2 has built-in support for JSON. Of course, if it is earlier than this version, there are many PHP versions available on the market, and it will be OK if you use it next time. Now we mainly talk about the built-in JSON supported by PHP. Very simple: two functions: json_encode and json_decode (similar to serialization ). One encoding and one decoding.

 

Eg:

$ Category1 = json_encode (array ("id" => "1000214", "category" => "domestic news "));
$ Category2 = json_encode (array ("id" => "1000215", "category" => "International News "));
$ Category5 = json_encode (array ("id" => "1000216", "category" => "Entertainment News "));

Echo $ category1 .'
';
Echo $ category2 .'
';
Echo $ category5 .'
';

 

Output:

{"Id": "1000214", "category": "/u56fd/u5185/u65b0/u95fb "}
{"Id": "1000215", "category": "/u56fd/u9645/u65b0/u95fb "}
{"Id": "1000216", "category": "/u5a31/u4e50/u65b0/u95fb "}

Eg:

 

Var_dump (json_decode ($ category1 )).'
';

Output:

 

Object (stdClass) [33] public 'id' => string '000000' (length = 7) public 'Category '=> string 'Entertainment News' (length = 12)

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.