up vote 0 down vote favorite
share [g+] share [fb]

I am building a website in asp.net mvc and jquery. I am parsing json objects and sending them from server side to client side. From some reason when I try calling the object it doesn't work. Here is how one of my objects looks when calling console.log(data) on the jquery callback

{
"songs": [
{
     "SongId": 1,
     "Name": "Black Eyed Peas - The Time (Dirty Bits)",
     "VideoID": "D7K3wFXJFsQ",
     "LastUpdated": "/Date(1299951907000)/"
},
{
     "SongId": 2,
     "Name": "Paramore - The Only Exception",
     "VideoID": "-J7J_IWUhls",
     "LastUpdated": "/Date(1299951907000)/"
  }
 ]
}

and here is how I try calling it:

console.log(data.songs)

Edit 1 When trying to specy the value as string, right in the client side (writing the string as literal), it works fine.

On the server side I am using JsonResult as the return type.

This keeps giving me an undefined value. Why?

Thank you

link|improve this question

72% accept rate
3  
Can you show us the code for how you are sending the JSON to the client (your controller method) as well as a more significant portion of the view method? (Your error message indicates that data.songs isn't ever receiving the value. I don't believe your problem has anything to do with the formatting of the data.) – JasCav Mar 12 '11 at 22:03
this is what I see when performing console.log(data) – vondip Mar 12 '11 at 22:05
3  
I'm assuming you're using .NET 3.5? If so, keep in mind that all response objects are wrapped in "d" as a preventative measure for JSON hacks. Try and see what is in d.data.song? Otherwise we'll need more code. – iivel Mar 12 '11 at 22:29
1  
break it down, take the text above and put it into a js var yourself. If it works then you know there is something else, if it doesn't then start smartly removing bits until you find the culprit code. Hope this helps. – Vinnyq12 Mar 12 '11 at 23:50
2  
@vondip: The best thing is to use a debugger and place a breakpoint where you receive the data, then look at the data in the debugger. There are debuggers built into IE8, IE9, Chrome, Opera, and Safari; you can get Firebug for Firefox; and for testing with earlier versions of IE, there's a free edition of VS.Net that you can use. – T.J. Crowder Mar 17 '11 at 7:08
show 4 more comments
feedback

1 Answer

Relevant information on how to do this here and here.

link|improve this answer
thank you Sharon, but this is not exactly my situation. I am having issues sending data from server side to client side, not the other way arround. – vondip Mar 17 '11 at 4:49
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.