In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
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!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.