Json-encode () How to decode it?

Source: Internet
Author: User
Tags urlencode

One way to solve the Chinese is to first convert the Chinese into another encoding format, then use Json_encode (), and then decode the JSON string with decoding. There is also a way to be resolved in the new version of PHP, shown in the code below.

The following is a code example

<?php
Header ("Content-type:text/html;charset=utf-8");
$arrayName = Array (' City ' = ' Guangdong ', ' goods ' = ' cookies ');
$arr = Json_encode ($arrayName);
echo $arr. " </br> ";
Var_dump (Json_decode ($arr));
echo "</br>";
Echo UrlDecode (Json_encode (Ch_json ($arrayName))). " </br> ";
/*
Requires PHP version above 5.4
Echo Json_encode ($arrayName, Json_unescaped_unicode);
*/
function Ch_json ($arr) {
if (Is_array ($arr)) {
foreach ($arr as $key = = $value) {
$arr [UrlEncode ($key)] = Ch_json ($value);
}
}else{
Return UrlEncode ($arr);
}
return $arr;
}
?>

PS: Here again for you to recommend a few more useful JSON online tools for everyone to refer to the use:

Online JSON code inspection, inspection, landscaping, formatting tools:
Http://tools.jb51.net/code/json
JSON Online formatting tool:
Http://tools.jb51.net/code/jsonformat
Online Xml/json Mutual Conversion tool:
Http://tools.jb51.net/code/xmljson
JSON code online formatting/landscaping/compression/editing/conversion tools:
Http://tools.jb51.net/code/jsoncodeformat
C Language Style/html/css/json code formatting beautification tool:
Http://tools.jb51.net/code/ccode_html_css_json

Json-encode () How to decode it?

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.