+1  A: 

You should be able to do this (the .d is because you're in .Net):

alert(data.d.nested.nestedString);

You're accessing the object just as you would in C#, just doing through the properties. The object d is the DummyType you're passing back, so just access the properties on it, the same as they're named in the C# type on the server, that's how they're serialized to the client.

If for some reason I've glossed over something and this doesn't work, remove the .d, but that shouldn't be the case.

Nick Craver
@Nick: Thanks a lot. Will mark your answer as the correct as soon as I'll be able to. But can you please elaborate on how this works? What does JQuery knows about my .NET objects and how? And can I iterate over my objects to get a generalized solution for printing the object and all it's sub-objects? Thanks again.
Oren A
@Oren - when the service responds you get a string (JSON) like this: `{ "d": { "error": "something", "nested": { "nestedString" : "something", "nestedInt": 0 } } }`, so it's a JavaScript object after being parsed on the client (jQuery does this), so that's how it knows :) Yes you can iterate over objects, arrays, etc, it depends on how you send them to the client, but for example of `NestedDummyType` was a list instead (`List<NestedDummyType> nesteds`) you could iterate over it like this: `$.each(data.d.nesteds, function() { alert(this.nestedString); });`
Nick Craver
@Oren - For the generalized printing...I'd use your console (Firebug or Chrome), there are by far the best tools for viewing the response object.
Nick Craver
+1  A: 

So if you do this:

success: function (data) { 
    alert(data.nestedInt)'
    alert(data.NestedDummyType.nestedString);
...

do you get what you expect?

EDIT: Just in case you have asp.net, the 2.0 and 3.5 return different values in the data and this parse function in the dataFilter will resolve that issue and work with both versions:

   $.ajaxSetup({
        data: "{}",
        datatype: "json",
        type: "POST",
        contentType: "application/json; charset=utf-8",
        dataFilter: function(data)
        {
            var msg;
            if (typeof (JSON) !== 'undefined' &&
                typeof (JSON.parse) === 'function')
                msg = JSON.parse(data);
            else
                msg = eval('(' + data + ')');
            if (msg.hasOwnProperty('d'))
                return msg.d;
            else
                return msg;
        },
        error: function(xhr, textStatus, errorThrown)
        {
  //handle errors
        }
    });
Mark Schultheiss
+1  A: 

Hi Oren,

If your server-side script effectively returns well-formed JSON, jquery will automatically parse it and the data object will contain the parsed object, i.e. your NestedDummyType object. Have you tried to do something like that in your success callback ?

success: function (data) {
    alert(data.nested.nestedString);
    alert(data.nested.nestedInt)
}
Pierre Henry
Check Nick's answer, I didn't no about .Net's '.d' object
Pierre Henry
A: 

Here's a useful little snippet I use in javascript when I want to find out about an object.

var s = "";
for(x in data)
  s += x + "=" + data[x] + "\r\n";
alert(s);

It will alert all methods/properties of the object data, but is not recursive (so you wouldnt see anything from nested.

Jamiec