FunctionarrayToJson ($ array) {arrayForRecursive ($ array, 'urlencode', true); $ json = json_encode ($ array); $ json = urldecode ($ json ); return $ json ;}
Function arrayToJson ($ array) {arrayForRecursive ($ array, 'urlencode', true); $ json = json_encode ($ array); $ json = urldecode ($ json ); return $ json ;}
Function arrayForRecursive (& $ array, $ function, $ applyToKeys_also = false) {static $ recursive_counter = 0; if (++ $ recursive_counter> 1000) die ('The array level is too deep! '); Foreach ($ array as $ key => $ value) {if (is_array ($ value) arrayForRecursive ($ array [$ key], $ function, $ applyToKeys_also); else $ array [$ key] = $ function (repalceSpecialSign ($ value); if ($ applyToKeysAlso & isString ($ key) {$ new_key = $ function ($ key); if ($ new_key! = $ Key) {$ array [$ new_key] = $ array [$ key]; unset ($ array [$ key]) ;}}$ recursive_counter --;}
Function struct2Array ($ item) {if (! Is_string ($ item) {$ item = (array) $ item; foreach ($ item as $ key => $ val) {$ item [$ key] = Struct2Array ($ val) ;}} return $ item ;}
/*** RepalceSpecialSign to replace the special symbol. * @ param str string a string * @ return str */function repalceSpecialSign ($ string) {$ string = preg_replace ("/\ s/", "", $ string ); $ string = str_replace ("\", "\", $ string); $ string = str_replace ("\ '", "\'", $ string ); $ string = str_replace ("\" "," \ "", $ string); $ string = strReplace (PHPEOL, '', $ string); $ string = str_replace (" \ n "," ", $ string); $ string = str_replace (" \ r ","", $ string); return $ string ;}
Call arraytojson.
Http://www.pooy.net/original-php-json-function-json-format.html