ASMX Json Serialization in 3.5 Framework.
am 01.04.2008 17:29:12 von bathamI created a asp.net web site with a web service in it.
My web service returns a object "Person" which is serialized into
JSON, when I make a ajax call to this service this is my return
output.
{"d":{"__type":"Person","FirstName":"Foo","LastName":"Goo"," Age":
99,"Address":{"Street":"One Microsoft
Way","City":"Redmond","State":"WA","Zip":98052}}}
My Question is where did that "d' and "__type" come from and is there
a way I can get rid of those two.
I want my end result to be this.
{"FirstName":"Foo","LastName":"Goo","Age":99,"Address":{"Str eet":"One
Microsoft Way","City":"Redmond","State":"WA","Zip":98052}}
help is really appreciated. I am attaching a copy of the source code.
Nothing has been changed in the web.config.
Thanks,
Shailendra
------------------------------------------------------------ ------------------------------------------------------------ ------------------------------
using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Web.Script.Services;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class MyWebService : System.Web.Services.WebService
{
public MyWebService()
{
}
[WebMethod]
[ScriptMethod(UseHttpGet = true,
ResponseFormat=ResponseFormat.Json)]
public Person CreatePerson()
{
Person p = new Person()
{
FirstName = "Foo",
LastName = "Goo",
Age = 99,
Address = new Address
{
Street = "One Microsoft Way",
City = "Redmond",
State = "WA",
Zip = 98052
}
};
return p;
}
}
------------------------------------------------------------ ------------------------------------------------------------ ------------------------------
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
------------------------------------------------------------ ------------------------------------------------------------ ------------------------------
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
///
/// Summary description for Person
///
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
public Address Address { get; set; }
}
------------------------------------------------------------ ------------------------------------------------------------ ------------------------------
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
///
/// Summary description for Address
///
public class Address
{
public string Street { get; set; }
public string City { get; set; }
public string State { get; set; }
public int Zip { get; set; }
}