Json_decode returned error code 4 solution

Source: Internet
Author: User
It may be caused by incompatible PHP versions or incorrect json format. You can try the following code: functionjsonEncode ($ data) {if (2func_num_args () {$ callee _ FUNCTION __; returnjson_format_scalar (strval (func_get_arg (1 ))). :. $ callee ($ data);} is_object ($ data

It may be caused by incompatible PHP versions or incorrect json format. Try the following code: function jsonEncode ($ data) {if (2 = func_num_args () {$ callee =__ FUNCTION __; return json_format_scalar (strval (func_get_arg (1 ))). ":". $ callee ($ data);} is_object ($ data

It may be caused by incompatible PHP versions or incorrect json format.
Try the following code:

Function jsonEncode ($ data) {if (2 = func_num_args () {$ callee =__ FUNCTION __; return json_format_scalar (strval (func_get_arg (1 ))). ":". $ callee ($ data);} is_object ($ data) & $ data = get_object_vars ($ data); if (is_scalar ($ data )) {return json_format_scalar ($ data);} if (emptyempty ($ data) {return '[]';} $ keys = array_keys ($ data ); if (is_numeric (join ('', $ keys) {$ data = array_map (_ FUNCTION __, $ data); return '['. join (', ', $ Data ). ']';} else {$ data = array_map (_ FUNCTION __, array_values ($ data), $ keys); return '{'. join (',', $ data ). '}' ;}} function json_format_scalar ($ value) {if (is_bool ($ value) {$ value = $ value? 'True': 'false';} else if (is_int ($ value) {$ value = (int) $ value;} else if (is_float ($ value )) {$ value = (float) $ value;} else if (is_string ($ value) {$ value = addcslashes ($ value, "\ n \ r \" \/\ "); $ value = '"'. preg_replace_callback ('| [^ \ x00-\ x7F] + |', 'json _ utf_slash_callback', $ value ). '"';} else {$ value = 'null';} return $ value;} function json_utf_slash_callback ($ data) {if (is_array ($ data )) {$ chars = str_split (iconv ("UTF-8", "UCS-2", $ data [0]), 2); $ chars = array_map (_ FUNCTION __, $ chars); return join ("", $ chars);} else {$ char1 = dechex (ord ($ data {0}); $ char2 = dechex (ord ($ data {1 })); return sprintf ("\ u % 02 s % 02 s", $ char1, $ char2) ;}} function json_utf_slash_strip ($ data) {if (is_array ($ data )) {return $ data [1]. iconv ("UCS-2", "UTF-8", chr (hexdec ($ data [2]). chr (hexdec ($ data [3]);} else {return preg_replace_callback ('/(?
 ', 'Null'), $ data); $ data = preg_replace_callback ('/# \ d +/',__ FUNCTION __, $ data); // suppress an error, JSON with errors such as {123 ###} cannot be converted into a PHP array @ $ data = eval ("return $ data;"); $ strings = $ count = 0; return $ data;} elseif (count ($ data)> 1) {// storage string $ strings [] = json_utf_slash_strip (str_replace (array ('$ ', '\/'), array ('\ $', '/'), $ data [0]); return '#'. ($ count ++);} else {// read the stored value $ index = substr ($ data [0], 1); return $ strings [$ index];}

Original article address: json_decode returned error code 4 solution. Thank you for sharing it with me.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.