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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:38:39+00:00 2026-05-23T11:38:39+00:00

UPDATE: So I’ve figured it out! All I had to do was use jQuery.parseJSON();

  • 0

UPDATE: So I’ve figured it out! All I had to do was use jQuery.parseJSON(); and it converted the JSON string into a JSON Object. Here is the updated code:

$.ajax({
  type: "POST",
  url: "GetEEs.aspx/GetNextEEs",
  data: "{recordID:" + lastItem + "}",
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  success: function (msg, textStatus, jqXHR) {
    var jObject = jQuery.parseJSON(msg.d);
    ddl.length = 0;
    $.each(jObject.d, function () {
      $.each(this, function (index, item) {
        addItemToDDL(ddl, item.Display, item.Value);
      });
    });
  },
  error: function (xhr, ajaxOptions, thrownError) {
    alert(xhr.status);
    alert(thrownError);
  }
});

Ok, I’ve written a function to query a table and return a dataset, then convert it to JSON so the page can use it. The function is below:

    <WebMethod()> _
    Public Shared Function GetNextEEs(ByVal recordID As Integer) As ArrayList
        If Not recordID.Equals(0) Then
            Dim sql As String = "SELECT TOP 500 * FROM cbotest WHERE ID > " & recordID
            Dim arr As New ArrayList

            Using dr As SqlDataReader = Mangrove.SqlHelper.ExecuteReader("...")
                While dr.Read()
                    arr.Add(New ArrayList() From { _
                     New With { _
                      Key .Value = dr("code").ToString, _
                      Key .Display = dr("description").ToString _
                     }
                    })
                End While
            End Using

            Return arr
        Else
            Throw New ApplicationException("Invalid Record ID")
        End If
    End Function

The function works great in .Net 4, but I can’t use it with .Net 2. So I found a JSON.Net Object called Jayrock. I changed my function to use it and everything works. Here is the revised function:

<WebMethod()> _
Public Shared Function GetNextEEs(ByVal recordID As Integer) As String
    If Not recordID.Equals(0) Then
        Dim sql As String = "SELECT TOP 500 * FROM cbotest WHERE ID > " & recordID
        Dim json As JsonObject = New JsonObject()
        Dim items As JsonArray = New JsonArray()

        Using dr As SqlDataReader = Mangrove.SqlHelper.ExecuteReader("...")
            While dr.Read()
                Dim item As JsonArray = New JsonArray()
                Dim itemArr As JsonObject = New JsonObject()

                itemArr.Add("Value", dr("code").ToString)
                itemArr.Add("Display", dr("description").ToString)

                item.Add(itemArr)
                items.Add(item)
            End While
        End Using

        json.Add("d", items)

        Using writer As JsonWriter = New EmptyJsonWriter()
            json.Export(writer)
            Return json.ToString
        End Using
    Else
        Throw New ApplicationException("Invalid Record ID")
    End If
End Function

The only problem is when it returns the JSON, the page can’t parse it.

Here is an example of the outputs from both functions:

First Version:
[object Object],[object Object],[object Object], ...

Revised Version:
{"d":[[{"Value":"501","Display":"Record Number 501"}],[{"Value":"502","Display":"Record Number 502"}], ...

As you can see, the revised version returns an actual string (That contains the correct data) where as the first version returned a JSON Object. I know it’s because of the function returning as a String, but for the life of me, I can’t figure out how to return a JSON Object using the revised code.

Does anybody have an idea on how to do this, or a better solution? I’m stumped! Also, please remember that this is for .Net 2 (sucks, I know :/)

Thank you for your time!

EDIT
Here is some of the client side code that I’m using:

$.ajax({
  type: "POST",
  url: "GetEEs.aspx/GetNextEEs",
  data: "{recordID:" + lastItem + "}",
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  success: function (msg, textStatus, jqXHR) {
    //alert(msg.d);
    document.getElementById('lbl').innerHTML = msg.d;
    ddl.length = 0;
    $.each(msg.d, function () {
      $.each(this, function (index, item) {
        addItemToDDL(ddl, item.Display, item.Value);
      });
    });
  },
  error: function (xhr, ajaxOptions, thrownError) {
    alert(xhr.status);
    alert(thrownError);
  }
});

I had an alert(item); inside of the inner-most loop. It was going letter by letter through the string.

  • 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-23T11:38:40+00:00Added an answer on May 23, 2026 at 11:38 am
    $.ajax({
      type: "POST",
      url: "GetEEs.aspx/GetNextEEs",
      data: "{recordID:" + lastItem + "}",
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function (msg, textStatus, jqXHR) {
        var jObject = jQuery.parseJSON(msg.d);
        ddl.length = 0;
        $.each(jObject.d, function () {
          $.each(this, function (index, item) {
            addItemToDDL(ddl, item.Display, item.Value);
          });
        });
      },
      error: function (xhr, ajaxOptions, thrownError) {
        alert(xhr.status);
        alert(thrownError);
      }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update : It turns out I had (hidden away in my POCO objects) a
Update: Check out this follow-up question: Gem Update on Windows - is it broken?
Update: Now that it's 2016 I'd use PowerShell for this unless there's a really
UPDATE - A comprehensive comparison, updated as of February 2015, can be found here:
Update: Thanks for the suggestions guys. After further research, I’ve reformulated the question here:
UPDATE 4.0 Seems like iOS 4.0 changed something here. Same code producing incorrect backgrounds
UPDATE I have reverted back to Jquery 1.3.2 and everything is working, not sure
UPDATE: Thanks for all your help guys! I just need to take a litte
Update 2: thanks again to @deepak-azad, I managed to solve my problem : here
Update : Properly initialising string with char string[sizeof buffer - 1] has solved the

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.