Tuesday, 10 September 2013

JSON returned from ASP.NET not usable in JS

JSON returned from ASP.NET not usable in JS

I'm returning a DataSet converted to JSON via a jQuery AJAX call, all is
well! The request I receive back is:
LOG: {"Table":[[2,"BlackBerry
Tour","2013-09-10","2013-09-13","Project"],null]}
Looks valid to me, also ran it through JSLint validator, again, all is
well! Now, whenever I try to access any of this data, I simply receive
undefined from the following:
var dataObject = data.d //data.d is the response from the server and what
is logged above
console.log(dataObject.Table) //undefined
console.log(dataObject["Table"]) //undefined
Now, if I run JSON.parse(dataObject), I can then access it alright. This
is a problem right now however, since the site this will reside on sticks
IE into IE7 mode, and JSON is always undefined according to IE (I know,
IE7, it's out of my hands tho).
So my question is why can I not use the returned JSON as is? why must I
run it through JSON.parse before using it? More info is available on
request (AJAX call, DataSet converter, etc)

No comments:

Post a Comment