But there's a problem.
Although JS is very handy for decoding JSON, coding does not seem to be a good idea ...
In the spirit can lazy is lazy, not lazy also as lazy as possible principle, the old dog a bit
It really made me find out.
PHP directly with Json_decode can be decoded, it is very convenient to use
Copy Code code 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");
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]=a;
}
Return "{" +aa.join (",") + "}";
}