Home > Backend Development > PHP Tutorial > json_encode supports Chinese after adding options parameter, json_encodeoptions_PHP tutorial

json_encode supports Chinese after adding options parameter, json_encodeoptions_PHP tutorial

WBOY
Release: 2016-07-13 10:23:40
Original
1367 people have browsed it

json_encode supports Chinese after adding options parameter, json_encodeoptions

-------------------------- -------------------------------------------------- --------------------------

<span>header</span>('content-type:text/html;charset=utf-8'<span>);
</span><span>$a</span> = '中文'<span>;
</span><span>echo</span> json_encode(<span>$a</span>);<span>//</span><span>5.3版本以前,无参数情况输出 "\u4e2d\u6587"</span>
<span>echo</span> json_encode(<span>$a</span>, JSON_UNESCAPED_UNICODE); <span>//</span><span> "中文"</span>
Copy after login

@黑eyedpoet

What is the options parameter of function(options) in the init attribute of the json object in methods? The actual parameter

cannot be found in the entire page

Your understanding is wrong. This is JS code. In fact, the built-in JS object is very small. You may put what you see into the programming framework and understand JS before learning programming methods for a certain framework. characteristic. You need to understand the object better under JS and it will not be difficult to understand the above code.
(1)$. extension (options, customoptions), seen from the code itself, $. Extend is not defined here, so there's no answer to what exactly it does. But in commonly used programming frameworks such as jQuery, this function mainly implements the properties and methods of objects from customoptions to the options object, which is what you call "expansion".

(2) JS type has weak or no language restrictions, so the parameter can be any type of object, usually, generally extending the combined object, including properties and functions of the object, so that you can see what it is " It is normal for objects to extend" functionality or "extend" other characteristics.
(3), choose your code to define the object (when the object is defined by {} object) instead of JSON, JSON refers to the string expression of the object, there is no string JSON format, you need to learn Understand the different definitions of writing JSON strings in JS code and programs. So, through the definition of the function, but no JSON here.

For the problem of json_encode

Isn't this because the two Chinese characters were encoded into unicode format after you encoded it?
The 'Shia' in unicode encoding format is \u5e0c\u4e9a

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/834765.htmlTechArticlejson_encode supports Chinese after adding options parameter, json_encodeoptions --------------- -------------------------------------------------- ---------------------------------- header ('con...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template