Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to solve the problem of parsing json returned by php server from app to null

Shulou Source: shulou.com Published: 2022-06-02 09:21:56 09月16日 Update

This article mainly explains "how to solve the problem of json parsing to null returned by the php server from the app side". The content of the article is simple and clear, and it is easy to learn and understand. please follow the editor's train of thought to slowly deepen, together to study and learn "how to solve the php server from the app side to resolve the json parsing to null" bar!

Data from the post,get on the app side or from other pages is usually in the form of an array. Because the array form is not easy to transfer, it is usually transferred to json and then sent. We thought that the sender json_encode () and the receiver json_decode () solved the problem, but it turns out that json_decode () is followed by NULL.

The general reaction is that one parameter "true" is missing, but when you go back, it is json_decode ($data,true); how can it be NULL? Is it coding, not ah, direct printing after receiving is in the form of a complete json string, in the online json parsing website, it can be parsed normally.

So what's going on? In fact, it is the problem of code translation.

You can use json_last_error_msg (); locate the problem

Correct parsing can be achieved using the following methods.

$data = stripslashes (html_entity_decode ($info)); / / $info is the passed json string

$data = json_decode ($data,TRUE)

At this point, $data is the parsed array!

The html_entity_decode () function converts HTML entities to characters.

The stripslashes () function removes the backslash.

You can also use these methods:

Solution 1:

Htmlspecialchars_decode ($str)

Solution 2:

Function removeBOM ($str) {

If (0 = strpos (bin2hex ($str), 'efbbbf')) {

Return substr ($data, 3)

}

Return $data

}

RemoveBOM ($str)

Solution 3:

Stripslashes (decodeUnicode ($str))

Thank you for reading, the above is the content of "how to solve the problem of json parsing to null returned by php server from app side". After the study of this article, I believe you have a deeper understanding of how to solve the problem of json parsing to null returned by php server from app side, and the specific usage needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Problems services characters that is forms arrays ways learning functions contents functions strings methods coding not easy parameters things entities ideas situations Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Linux Huawei vpn Apple