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 3498530
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:30:05+00:00 2026-05-18T12:30:05+00:00

I have an ASP.NET webservice method that returns a generics list (List'<‘Construct>) serialized as

  • 0

I have an ASP.NET webservice method that returns a generics list (List'<‘Construct>) serialized as JSON, using code such as this:

 [WebService(Namespace = "http://tempuri.org/")]
 [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
 [ScriptService]
 public class TestService : System.Web.Services.WebService {

 [WebMethod]
 [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
 public string GetOccupationListJSON(int SOCLevel)
 {
   Construct NewConstructList = new ConstructList();
   DataContractJsonSerializer serializer = new DataContractJsonSerializer(ConstructList.GetType());
   MemoryStream ms = new MemoryStream();
   serializer.WriteObject(ms, NewConstructList);
   string json = Encoding.Default.GetString(ms.ToArray());
   return json;
 }
}

I then use jQuery to call this method, and get the JSON data, like so:

function GetCustomerList() {
    $.ajax({
        type: "POST",
        url: "/WebService.asmx/GetConstructList",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) { LoadConstructData(data.d); },
        failure: function() { alert("Sorry, we were unable to find the constructs."); }
   });
}

The JSON result looks like this:
[
{
"ConstructLabel": "Construct label 1",
"ConstructType": 2,
},
{
"ConstructLabel": "Construct label 2",
"ConstructType": 3,
}
]

I then want to iterate through the elements in the ConstructList in the JSON data. This is the function that gets called on when the jQuery Ajax call is successful:

function LoadConstructData(data) {
    for (var i = 0, len = data.length; i < len; ++i) {
        var Construct = data[i];
        var ConstructLabel = Construct.ConstructLabel
        var ConstructType = Construct.ConstructType;
     }
  }

I assumed (from looking elsewhere) that accessing the JSON data through the index would provide me with access to the underlying object at that index, so that I can then work with it to access its properties.
However, when i=0 and I do var Construct = data[i]; I get the character at the i position of the data array ([), and in the next iteration I get the second character ({). So clearly I am accessing the elements of a string array rather than the JSON data object.
How do I make sure that the data returned by the webservice gets into proper JSON format, so that I can iterate through the object elements within it?

  • 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-18T12:30:05+00:00Added an answer on May 18, 2026 at 12:30 pm

    You shouldn’t manually serialize the JSON. The ScriptService will do that for you automatically if you define it like this:

    [WebMethod]
    public List<Construct> GetConstructList()
    {
      return new ConstructList();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET webservice (.asmx) with a simple method that reads something from
I have some ASP.NET page and webservice WebMethod() methods that I'd like to add
I have a webservice that exists in an asp.net website. When I publish the
I have an ASP.net web service that I'm using for a web application which
I have an ASP.NET webservice with along the lines of: [WebService(Namespace = http://internalservice.net/messageprocessing)] [WebServiceBinding(ConformsTo
I have a control application - using asp.net webservices. I have a timer which
I have ASP.NET web pages for which I want to build automated tests (using
I have asp.net form that contains fields. When I access this window, my javascript
We are using Excel to convert SpreatSheetML to XLS in an ASP.NET webservice. Moreover,
I have a web service that returns a raw string of JSON data (sample

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.