Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to solve the problem of Chinese garbled codes in json Chinese strings

Shulou Source: shulou.com Published: 2022-06-01 14:03:13 10月02日 Update

What this article shares with you is about how to solve the problem of Chinese garbled code in json Chinese strings. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

Case one

When I was asked this question in the interview today, I obviously knew it before, but after I didn't touch it for half a year, I just didn't think of it, so I had to bravely say that the json assistant function that came with tp would not have this problem, and the scene was very awkward for a time.

Look at the example.

Output after execution of the above code:

{"a": 1, "b": 2, "c": 3, "d": 4, "e": 5}

If you want to encode the data source (usually an array), value contains Chinese, after json_encode processing, the output is unicode encoding.

Output after execution of the above code:

{"a": "\ u811a\ u672c\ u4e4b\ u5bb6"}

The underlying layer of PHP has already done unicode processing. If it is not intuitive enough, you can use urlencode and urldecode methods to bypass the process of transcoding to unicode:

First urlencode encoding and then urldecode decoding

$arr = array ('averse = > urlencode ('')); echo urldecode (json_encode ($arr))

Output after execution of the above code:

{"a": ""}

The above is how to solve the problem of Chinese garbled code in json Chinese strings. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Tags: Chinese coding code problem output garbled character string function more case knowledge article result processing practical awkward intuitive not enough two Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Information Linux NVidia Redmi