I have been fascinated by JSON these days, and even some XML work in the project has been handed over to JSON. JSON is much more convenient than XML, 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.
The Code is as follows:
Function json_encode_js (aaa ){
Function je (str ){
Var a = [], I = 0;
Var pcs = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
For (; 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 (",") + "}";
}