I have this stadard code for receiving a class from a web service:
function getStuff() {
var callParams = "{'param1':'" + "oren" + "'}"
$.ajax({
type: "POST",
url: "http://192.168.5.223:8989/TolunaAPI.asmx/GetDummyType",
data: callParams,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert(data);
....
This give an alert that says: [object Object].
I tried reading some related posts here and on JQuery documentation, but I can’t understand what exactly is the “data” object.
What the web service returns is and object named DummyType:
public class DummyType
{
public ErrorTypes error;
public NestedDummyType nested;
public DummyType() { }
public DummyType(string paramName)
{
error = ErrorTypes.None;
nested = new NestedDummyType();
}
}
}
Which as you see has another object in it, namely NestedDummyType:
public class NestedDummyType
{
public string nestedString;
public int nestedInt;
public NestedDummyType()
{
nestedString = "Hello from nested";
nestedInt = -1;
}
}
All of these are supposed to be returned in json format, but as mentioned, I can't seem to be able to interpret the received data.
How is this done?
Thanks.
You should be able to do this (the
.dis because you’re in .Net):You’re accessing the object just as you would in C#, just doing through the properties. The object
dis theDummyTypeyou’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.