Use Json_encode and Json_decode to pass data containing special characters in PHP

Source: Internet
Author: User

Json_decode

Mixed Json_decode (String $json [, bool $assoc = False [, int $depth = [, int $options = 0]]])
Accept a JSON-formatted string and convert it to a PHP variable

Json_encode

String Json_encode (mixed $value [, int $options = 0])
Returns the JSON form of value values

For example, in the interface_x need to get the data passed in the interface_y, and data contains special characters, you can put these special characters in the interface_y array, and then json_encode into JSON
The formatted string, passed to Interface_x, is json_decode in the interface_x.

$json 2 = Json_decode ($json, true);//echo "Json2:";//var_dump ($json 2);

Interface_y strings containing special characters are processed, stored in arrays, and Json_encode:

$value = ' ~!@#$%^&* () _+-={}: "; <>?/\123456789123 '; $data = Array (" key "= = $value); $json = Json_encode ($data );//echo "JSON:". " \ n ";//var_dump ($json);

Json_decode an array of incoming JSON data in interface_x.

Reference:

http://php.net/manual/zh/function.json-decode.php

http://php.net/manual/zh/function.json-encode.php

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The above describes the use of PHP Json_encode and Json_decode to pass the data containing special characters, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.