When researching and writing a typecho data to halo plug-in today

Because the typecho data needs to be converted to json before it can be imported into halo,

I used it directly at first:

echo json_encode($arry);

The returned results are as follows:

"name": "\u9ed8\u8ba4\u5206\u7c7b",
This should be Chinese, but the Chinese is encoded by unicode.

Http://---- This should be http, but all slashes have been escaped.

In order to facilitate data processing, the Chinese of the accepted data must not be encoded by unicode, and the slash does not need to be escaped.

First, Baidu found a solution after consulting with its friend @ wibus
PHP function: json_encode Chinese unicode encoding and slash escape solution - Fu Jie Blog (fujieace. com)

resolvent

First, let me tell you something about json_encode in PHP. I believe you all know:

 
In PHP, json_encode has several constants, such as:

JSON_UNESCAPED_UNICODE//Chinese is not converted to unicode

JSON_UNESCAPED_SLASHES//Do not escape backslash

......

 
Here are two methods. Let me give you a brief introduction. Take me as an example, let the two methods take effect at the same time as follows:

 

The first method

Add "|" between the two parameters, and the code is as follows:

 <? php echo json_encode($array, JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE);

The second method

Because JSON_UNESCAPED_UNICODE and JSON_UNESCAPED_SLASHES are constants;

JSON_UNESCAPED_UNICODE = 256

JSON_UNESCAPED_SLASHES = 64

JSON_UNESCAPED_UNICODE + JSON_UNESCAPED_SLASHES = 320

 

Two simultaneously effective codes can be used as follows:

 <? php echo json_encode($array,320);

It's really solved~
Final effect:

A wave of halo import data was tested, and classified data was successfully imported~

By the way, when the typecho data is transferred to the halo plug-in, it is the time of transferring to the halo~
Goodbye typecho, hello hello!

My blog will be synchronized to the Tencent Cloud Developer Community, inviting everyone to join us: https://cloud.tencent.com/developer/support-plan?invite_code=3b3psvi2ezi8c