I have a Javascript object like this:
var jsonDataActual = {
"source": [{
"name": "testCaption0",
"desc": "testDescrip0",
"values": [{
"from": "/Date(1338811241074)/",
"to": "/Date(1346760041074)/",
"label": "testLabel0",
"customClass": "GanttRed"
}]
}],
"navigate": "scroll",
"scale": "weeks",
"maxScale": "months",
"minScale": "days",
"itemsPerPage": 11,
"onItemClick": function (data) { },
"onAddClick": function (dt, rowId) { }
};
it works fine for me. Now, because of my requirement and need, am making this entire object(including braces i.e.{ } and semicolon ;) as a string on server side (C#) and returning it to an ajax call (web Method) using a server side method:
in the server side method I do something like this:
return new JavaScriptSerializer().Serialize(jsonData);
but now this entire returned data (inside Success: function(msg){ var s=msg.d}
) is treated as string, hence it doesn't work.
I tried these:
1. var obj = eval('{' + msg.d +'}'); (removing beginning and ending braces in msg.d)
typeof(obj) is string. failed
2. eval('var obj ='+msg.d); (including beginning and ending braces in msg.d)
typeof(obj) is string. failed
3. var obj= jQuery.parseJson(msg.d);
typeof(obj) is string. failed
4. var obj = new Object();
//var obj = {};
obj=jQuery.parseJson(msg.d).
typeof(obj) is string. failed.
please help. How can I convert a server side returned json into object?
Why not is it working for me??. Is it because of structure of my json object??
and why does jsonDataActual
works for me but not when sent as a string???
Please Help.....