Note that there are some explanatory texts on larger screens.

plurals
  1. POasp.net 2.0 asmx WebService Exclude __type in JSON Response
    primarykey
    data
    text
    <p>I am trying to determine how to exclude <code>__type</code> in my JSON response from an asmx WebService.</p> <p>The class that I am returning is constructed as follows.</p> <pre><code>public class MyClassName { private string _item1 = string.Empty; private string _item2 = string.Empty; public string item1 = { get { return _item1; } set { _item1 = value; } } public string item2 = { get { return _item2; } set { _item2 = value; } } } public class MyClassName_List : List&lt;MyClassName&gt; { public MyClassName_List() {} } </code></pre> <p>I then have a Data Access Layer and Business Logic Layer that returns a populated instance of <code>MyClassName_List</code>. My WebMethod is setup as follows.</p> <pre><code>using System; using System.Collections.Generic; using System.Web; using System.Web.Services; [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] [System.Web.Script.Services.ScriptService] public class MyClassName_WebService : System.Web.Services.WebService { [WebMethod] public MyClassName_List GetList() { return MyClassName_List_BusinessLogicLayer.GetList(); } } </code></pre> <p>The JSON object return is structured as follows.</p> <pre><code>[ { item1: "item1-1 text", item2: "item1-2 text", __type: "NamespaceUsed.MyClassName" }, { item1: "item2-1 text", item2: "item2-2 text", __type: "NamespaceUsed.MyClassName" }, ] </code></pre> <p>I just want to return the JSON object as follows.</p> <pre><code>[ { item1: "item1-1 text", item2: "item1-2 text" }, { item1: "item2-1 text", item2: "item2-2 text" } ] </code></pre> <p>I have tried the suggestions from <a href="https://stackoverflow.com/questions/627356/how-to-not-serialize-the-type-property-on-json-objects">here</a>, but I can not seem to implement it properly. Any help on this is much appreciated!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload