I would recommend using JSON.stringify
if you can fixed IE modes to IE8 and IE8 standards. JSON.stringify
will serializes an object and very easy to use. Most modern browsers support this method natively, but for those that don't, you can include a JS version
and If you can not fixed your IE modes then use below method to convert object to string.
Function:
function objToString (obj) {
var tabjson=[];
for (var p in obj) {
if (obj.hasOwnProperty(p)) {
tabjson.push('"'+p +'"'+ ':' + '"' +obj[p] + '"');
}
} tabjson.push()
return '{'+tabjson.join(',')+'}';
}
Call a function:
var obj = {"name": "XXX", "age": "27"};
objToString(obj );
Output:
"{"name":"XXX","age":"27"}"