Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to convert json objects into strings in JSS
How to convert json objects into strings in JSS
Obj2str: function (o) {

if (o == undefined) {

Return'';

}

var r =[];

If (typeof o == "string ") returns" \""+o.replace(/([\"\\])/g ([\ "\])/g," \\$ 1 "). Replace (/(\n)/g, "\\n"). Replace (/(\r)/g, "\ r"). Replace (/(\t)/g, "\ \ t ")+" \ ";;

if (typeof o == "object") {

If (! o.sort) {

For (variable i in o)

r . push(" \ "+I+" \ ":"+fn。 obj 2 str(o[I]);

If (! ! All the files &&! /^\n? Function \ s * toString \(\)\ s * \ n? \ s * \[ native code \]\n? \s*\}\n? \s*$/。 test(o.toString)) {

r . push(" toString:"+o . toString . toString());

}

r = "{" + r.join() + "} "

} Otherwise {

for(var I = 0; I<o. Length; i++)

Push (fn. Obj2str(o[i])

r = "["+r . join()+"]";

}

return r;

}

Returns o.toString (). replace(/\"\:/g,' " ":" " ');

}