ASMX Json Serialization in 3.5 Framework.

ASMX Json Serialization in 3.5 Framework.

am 01.04.2008 17:29:12 von batham

I 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" %>

www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


:: Test ASMX JSON Serialization ::








ScriptMode="Release">





Call Web Service using
Script Manager




Call Web Service using
YUI








------------------------------------------------------------ ------------------------------------------------------------ ------------------------------
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; }
}

Re: ASMX Json Serialization in 3.5 Framework.

am 01.04.2008 18:08:29 von Michael Justin

batham schrieb:

> {"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

"d" and "Person" might be name spaces / class names / other metadata of
the serialized object. IIRC this was the case when a Java object is
transformed to JSON using the Apache ActiveMQ message broker.

Michael

Re: ASMX Json Serialization in 3.5 Framework.

am 01.04.2008 18:25:36 von batham

On Apr 1, 9:08=A0am, Michael Justin
wrote:
> batham schrieb:
>
> > {"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
>
> "d" and "Person" might be name spaces / class names / other metadata of
> the serialized object. IIRC this was the case when a Java object is
> transformed to JSON using the Apache ActiveMQ message broker.
>
> Michael

So how do I get rid of those? I just want the JSON to be plain without
any extra root nodes.

Thanks,
Shailendra