Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7535003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:10:43+00:00 2026-05-30T06:10:43+00:00

I have a WebMethod that looks like this which is used to populate a

  • 0

I have a WebMethod that looks like this which is used to populate a jqGrid

[System.Web.Script.Services.ScriptService]
public class MyWebService: System.Web.Services.WebService
{
    [WebMethod]
    [Authorize(Roles = "Admin")]
    public object GetPeople(bool _search, double nd, int rows, int page, string sidx, string sord)
    {
        var tbl = new DynamicModel("ConnStr", tableName: "Person", primaryKeyField: "ID");
        var results = tbl.Paged(orderBy: sidx + " " + sord, currentPage: page, pageSize: rows);
        return results;
    }

}

“results” is a System.Dynamic.ExpandoObject with the properties Items, TotalPages, TotalRecords

The json I get back on the from the webservice looks like this

{
"d": [{
    "Key": "TotalRecords",
    "Value": 1
}, {
    "Key": "TotalPages",
    "Value": 1
}, {
    "Key": "Items",
    "Value": [
        [{
            "Key": "Row",
            "Value": 1
        }, {
            "Key": "ID",
            "Value": 1
        }, {
            "Key": "Name",
            "Value": "Test Template"
        }]
    ]
}]
}
} // Don't know why firebug put this extra bracket

Ideally I’d prefer that it comes back without all the Key and Value business as it bloats out the json unnecessarily and doesn’t play nicely with jqGrid.

Is there a way to change the way ASP.NET is handling the serialization of the ExpandoObject?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T06:10:44+00:00Added an answer on May 30, 2026 at 6:10 am

    It sounds like you’ve already figured this out, but here’s something I threw together a while back to do just that:

    public class ExpandoObjectConverter : JavaScriptConverter {
      public override IEnumerable<Type> SupportedTypes {
        get { return new ReadOnlyCollection<Type>(new List<Type>(new Type[] { typeof(ExpandoObject) })); }
      }
    
      public override IDictionary<string, object> Serialize(object obj, JavaScriptSerializer serializer) {
        ExpandoObject expando = (ExpandoObject)obj;
    
        if (expando != null) {
          // Create the representation.
          Dictionary<string, object> result = new Dictionary<string, object>();
    
          foreach (KeyValuePair<string, object> item in expando) {
            if (item.Value.GetType() == typeof(DateTime))
              result.Add(item.Key, ((DateTime)item.Value).ToShortDateString());
            else
              result.Add(item.Key, item.Value.ToString());
          }
    
          return result;
        }
        return new Dictionary<string, object>();
      }
    
      public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer) {
        return null;
      }
    }
    

    Then, you just need to add it to the <converters> section in your web.config, as shown in the MSDN article you linked to:

    <configuration>
      <system.web.extensions>
        <scripting>
          <webServices>
            <jsonSerialization>
              <converters>
                <add name="ExpandoObjectConverter" type="ExpandoObjectConverter"/>
              </converters>
            </jsonSerialization>
          </webServices>
        </scripting>
      </system.web.extensions>
    </configuration>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web service that looks like this: public class TheService : System.Web.Services.WebService
Ii have a web method that looks like this: [WebMethod] public int ImportData(System.Collections.Generic.List<Record> importRecords)
I have a web service that looks like this [WebMethod] public int Import(System.Collections.Generic.List<Record> importRecords)
I have a ASP.NET web service decorated with System.Web.Script.Services.ScriptService() so it can return json
I have a simple web service operation like this one: [WebMethod] public string HelloWorld()
I have a WebMethod that recives HTML as parameter somthing like this: Public Function
I have some ASP.NET page and webservice WebMethod() methods that I'd like to add
i have an ASP.NET web service that returning a custom entity object (Staff): [WebMethod]
Im trying to add an constructor to my webservice, that looks like this: public
I have some web methods in an asmx web service that currently look like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.