Today, the company is working on a function to connect data to the app. the other party transfers the data after the json escape, but it is not a standard json formatted data, we directly use json_decode to enter the original character. let's take a look at the solution of the year. Code such... today, the company is working on a function to connect data to the app. the other party transfers the data after the json escape, but it is not a standard json formatted data, we directly use json_decode to enter the original character. let's take a look at the solution of the year.
The code is as follows:
\u5c0f\u533a\u7eff\u5316\u5f88\u4e0d\u9519|||\u4e8c\u671f\u4ec0\u4e48\u65f6\u5019\u4ea4\u623f\u7684|||\u4e8c\u671f\u4ea4\u623f\u4e86|||\u548c\u683c\u6797\u4e91\u5885\u79bb\u5f97\u5f88\u8fd1|||\u5730\u7406\u4f4d\u7f6e
Can anyone understand the above code? I guess no one is there. I know it's json, so take a piece and test it.
echo json_decode('u683c\u8fd8\u4e0d\u9519');
No input is found. later we thought this is not a standard json. we can use an array to convert it.
$array =array('u683c\u8fd8\u4e0d\u9519');echo json_encode( $array ) ;
The result is:
["u683c\\u8fd8\\u4e0d\\u9519"]
This is not data in standard json format. I will parse it later.
$array = json_decode('["\u4e8c\u671f\u4ec0\u4e48\u65f6\u5019\u4ea4\u623f\u7684"]');
Print_r ($ array); ([0] => bang ??? {€ ?? Why ?? Hey? Cross ??) Yes
Garbled code. I guess this is a coding problem. I know that the json conversion code is uft8, and my page is gbk. I found the iconv function at that time.
$array = json_decode('["\u4e8c\u671f\u4ec0\u4e48\u65f6\u5019\u4ea4\u623f\u7684"]');echo iconv('utf-8','gbk',$array[0]);
The result is:
When will the second phase be handed over?
In this way, garbled characters are successfully converted into Chinese characters. please give it a try.
Site original tutorial: Reprinted with the source of http://www.phprm.com