PHP handles JSON string decoding to return null resolution, Jsonnull
This article explains how PHP handles JSON string decoding to return null. Share it for everyone's reference. Here's how:
In general,PHP uses the Json_decode () function for JSON string decoding, the first argument to pass a string, and the second parameter, if true, to return an array, or false to return an object. If NULL is returned, indicating an error, the output json_last_error (), the resulting integer value corresponding to the wrong hint . As shown in the following:
Json_last_error () is more common than the integer 4, which is a JSON string that was incomplete before Json_decode, so syntax error.
Then must be the client to submit the individual characters affect the format of the JSON, you can use JS to filter, you can solve the general problem, mainly filter returns, spaces, HTML tags.
The implementation code is as follows:
/** Filter function */function htmlEncode (str) { str = str.replace (/\s+/ig, '); str = str.replace (/&/g, "); str = str.replace (//g, "); str = str.replace (/(?: t| |v|r) *n/g, '
'); str = str.replace (/t/g, " ); str = str.replace (/x22/g, ' "'); str = str.replace (/x27/g, "'); str = str.replace (/"/g," "); return str;}
In this case, you must submit the JSON string data to the server-side processing, which can only be filtered by the client.
Other Json_decode ($STR) return null for some reasons:
1. $STR can only UTF-8 encoding
2. The element cannot end with a comma (unlike PHP's array)
3. Elements cannot use single quotation marks
4. There must be no spaces and \ n in the middle of the element value
If you encounter the above situation, you can follow the above method to deal with. I hope this article is helpful to everyone's PHP programming.
PHP receives the JSON returned by PHP, the parsed value is null
B.php must submit a cookie value when fetching JSON content, otherwise a.php will only return empty content.
PHP array is converted to JSON, and the string "Restaurant/café" is turned into JSON after it is displayed as null how can I display the string correctly
You can try it by using single quotation marks to get your keys.
$arr = Array (' Amenities ' =>array (' restaurant/café ' = = Array (' classroom ' = ' classroom ')));
echo Json_encode ($arr);
http://www.bkjia.com/PHPjc/872372.html www.bkjia.com true http://www.bkjia.com/PHPjc/872372.html techarticle PHP handles JSON string decoding to return null resolution, Jsonnull This article describes the PHP processing JSON string decoding return NULL resolution. Share it for everyone's reference. ...