title: Iterating through a Data Transfer Object inside the Web Method Call
body: <p>I am sending a DTO to a web service using JQuery, but i need to know how to iterate through the object when received at the web service call. Here is the code</p>
  
  <h2>JQUERY</h2>
  
  <pre><code>$(divButtonText).click(function() {
  
              var QuestionItems = {};
              var foundEmptyFields = false;
              var count = 1;
              $(".diverror").hide();
  
              $(".cmsquestions").each(function() {
  
                  var question = $($(this).find(".cmstextbox input")).val();
                  var radioValue = $($($('input[name="responsefields' + count + '"]:checked')).next()).text();
  
                  if (question.length &gt; 0) {
  
                      var questionnumber = $(".cmspagenumber").length;
  
                      if (questionnumber == 0) {
  
                          questionnumber = 1;
                      }
  
                      var QuestionItem = {};
  
                      QuestionItem.TitleID = data.d;
                      QuestionItem.Number = questionnumber;
                      QuestionItem.Question = question;
                      QuestionItem.FieldType = radioValue;
  
                      QuestionItems[count - 1] = QuestionItem;
                  }
                  else {
                      foundEmptyFields = true;
                      var error = $(this).find(".diverror");
                      $(error).show();
                  }
  
                  count += 1;
  
              });
  
              if (!foundEmptyFields) {
  
  
  
                  var DTO = { 'QuestionItems': QuestionItems };
                  var param = JSON.stringify(DTO);
                  Ajax_WebService(param, 'AddQuestion', AddQuestionServerResponse);
  
              }
  
          });
  </code></pre>
  
  <h2>WEBMETHOD</h2>
  
  <pre><code> &lt;WebMethod()&gt; _
    Public Function AddQuestion(ByVal QuestionItems As Object) As Integer
  
      For i As Integer = 0 To QuestionItems.Count - 1
  
  
  
      Next
  
  
  End Function
  </code></pre>
  
  <h2>EDIT</h2>
  
  <h2>WEB Service Call</h2>
  
  <pre><code>function Ajax_WebService(param, method, callback) {
  
  $.ajax({
      type: "POST",
      url: "CMSAdmin.asmx/" + method,
      data: param,
      dataType: "json",
      contentType: "application/json; charset=utf-8",
      success: function(data) {
          if (callback) {
              callback.call(null, data);
          }
  
      }
  });
  
  }
  </code></pre>
  
  <h2>EDIT</h2>
  
  <p>Ok i have changed the WebMethod to this</p>
  
  <pre><code> &lt;WebMethod()&gt; _
   Public Function AddQuestion(ByVal QuestionItems As List(Of QuestionItem)) As Integer
  
  
  
  
  End Function
  </code></pre>
  
  <p>I can now possibly iterate through the list items but my QuestionItem class is picking up values of nothing and empty, the QuestionItem class is here</p>
  
  <pre><code>Public Class QuestionItem
  
  
      Private _TitleID As Integer
      Private _Number As Integer
      Private _Question As String
      Private _FieldType As String
  
      Public ReadOnly Property TitleID() As Integer
          Get
              Return Me._TitleID
          End Get
      End Property
  
      Public ReadOnly Property Number() As Integer
          Get
              Return Me._Number
          End Get
      End Property
  
      Public ReadOnly Property Question() As String
          Get
              If Me._Question Is Nothing Then
                  Return String.Empty
              End If
              Return Me._Question
          End Get
      End Property
  
      Public ReadOnly Property FieldType() As String
          Get
              If Me._FieldType Is Nothing Then
                  Return String.Empty
              End If
              Return Me._FieldType
          End Get
      End Property
  End Class
  </code></pre>
  
  <p>Why is the properties returning null and empty values from the JSON Object, that class structure is the same as the JSON Class Structure?</p>