![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | ASMX Json Serialization in 3.5 Framework. 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":{"Street":"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" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:// www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>:: Test ASMX JSON Serialization ::</title> <script type="text/javascript" src="http://yui.yahooapis.com/2.5.1/ build/yahoo-dom-event/yahoo-dom-event.js"></script> <script type="text/javascript" src="http://yui.yahooapis.com/2.5.1/ build/connection/connection-min.js"></script> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Release"> <Services> <asp:ServiceReference Path="~/MyWebService.asmx" /> </Services> </asp:ScriptManager> <div> <a href="javascript:void(0)" id="a1">Call Web Service using Script Manager</a><br /> <br /> <a href="javascript:void(0)" id="a2">Call Web Service using YUI</a> </div> <script type="text/javascript"> var url = '/WebSite1/MyWebService.asmx/CreatePerson'; function _CallScriptManager(e) { MyWebService.CreatePerson(); } function _CallYUI(e) { YAHOO.util.Connect.initHeader('Content-Type','application/ json',true); YAHOO.util.Connect.asyncRequest('GET', url, {scope: this, cache: false}); } YAHOO.util.Event.addListener('a1', 'click', _CallScriptManager); YAHOO.util.Event.addListener('a2', 'click', _CallYUI); </script> </form> </body> </html> ------------------------------------------------------------------------------------------------------------------------------------------------------ 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> /// Summary description for Person /// </summary> 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> /// Summary description for Address /// </summary> public class Address { public string Street { get; set; } public string City { get; set; } public string State { get; set; } public int Zip { get; set; } } |
My System Specs![]() |
| | #2 (permalink) |
| | Re: ASMX Json Serialization in 3.5 Framework. batham schrieb: Quote: > {"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 the serialized object. IIRC this was the case when a Java object is transformed to JSON using the Apache ActiveMQ message broker. Michael |
My System Specs![]() |
| | #3 (permalink) |
| | Re: ASMX Json Serialization in 3.5 Framework. On Apr 1, 9:08*am, Michael Justin <michael.jus...@xxxxxx> wrote: Quote: > batham schrieb: > Quote: > > {"d":{"__type":"Person","FirstName":"Foo","LastName":"Goo","Age": > > 99,"Address":{"Street":"One Microsoft > > Way","City":"Redmond","State":"WA","Zip":98052}}} Quote: > > 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 any extra root nodes. Thanks, Shailendra |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| can't update .NET Framework 3.5 Service Pack 1 and .NET Framework 3.5(KB951847 | Windows Updates | |||
| XML Serialization | .NET General | |||
| ANN: Bricksoft IM(MSN) SDK For .NET Framework/.NET Compact Framework v1.2 released | Live Messenger | |||