But there is a problem.
Although JS decoding JSON is very convenient, there seems to be no good way to code it...
In the principle that you can be either lazy or lazy
I found it.
Json_decode can be directly used in PHP for decoding, which is quite convenient to use.
Copy codeThe Code is as follows:
Function json_encode_js (aaa ){
Function je (str ){
Var a = [], I = 0;
Var pcs = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
For (; I <str. length; I ++ ){
If (pcs. indexOf (str [I]) =-1)
A [I] = "\ u" + ("0000" + str. charCodeAt (I). toString (16). slice (-4 );
Else
A [I] = str [I];
}
Return a. join ("");
}
Var I, s, a, aa = [];
If (typeof (aaa )! = "Object") {alert ("ERROR json"); return ;}
For (I in aaa ){
S = aaa [I];
A = '"' + je (I) + '":';
If (typeof (s) = 'object '){
A + = json_encode_js (s );
} Else {
If (typeof (s) = 'string ')
A + = '"' + je (s) + '"';
Else if (typeof (s) = 'number ')
A + = s;
}
Aa [aa. length] =;
}
Return "{" + aa. join (",") + "}";
}