Use json_encode and json_decode in php to transmit data containing special characters

Source: Internet
Author: User
: This article describes how to use json_encode and json_decode to transmit data containing special characters in php. For more information about PHP tutorials, see.


Json_decode

Mixed json_decode (string $ json [, bool $ assoc = false [, int $ depth = 512 [, int $ options = 0])
Accept a JSON string and convert it to a PHP variable

Json_encode

String json_encode (mixed $ value [, int $ options = 0])
Return the JSON format of the value.

For example, interface_x needs to obtain the data transmitted in interface_y, and data contains special characters, so that these special characters can be stored in the array in interface_y, and then json_encode is converted into json
Format string, passed to interface_x, json_decode in interface_x.

$json2 = json_decode($json, true);//echo "json2:";//var_dump($json2);

Interface_y processes strings containing special characters, stores them into arrays, and performs json_encode:

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

In interface_x, json_decode is used to convert the input json data into an array.

Refer:

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

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

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

The above section describes how to use json_encode and json_decode to pass data containing special characters in php, including some content, and hope to help friends who are interested in PHP tutorials.

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.