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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:27:47+00:00 2026-05-28T05:27:47+00:00

I need to store a set of values which I get from my C#

  • 0

I need to store a set of values which I get from my C# code to a javascript array.
Im getting an error .. Can someone tell what the error is ?
Im using this jcode.

 $.get('Dataextract.aspx', function (data, textStatus) {
        alert('Status is ' + textStatus);//success
        alert('JSON data string is: ' + data);//string as below

    var JSONdata = data;
    eval(JSONdata);//error here-> expected ;
    alert(JSONdata.rowval[0].CustomerID);

}, 'text');

I am using an ajax query to retrieve an array of JSON object. the data objects value that i get is something like this as string.

{"rowval" :[{"CustomerID":12"Title":"Mr.""FirstName":"Johnny""MiddleName":"A.""LastName":"Caprio""CompanyName":"Bikes and Motorbikes""RowNumber":10},{"CustomerID":16"Title":"Mr.""FirstName":"Christopher""MiddleName":"R.""LastName":"Beck""CompanyName":"Bulk Discount Store""RowNumber":11},{"CustomerID":18"Title":"Mr.""FirstName":"David""MiddleName":"J.""LastName":"Liu""CompanyName":"Catalog Store""RowNumber":12},{"CustomerID":19"Title":"Mr.""FirstName":"John""MiddleName":"A.""LastName":"Beaver""CompanyName":"Center Cycle Shop""RowNumber":13},{"CustomerID":20"Title":"Ms.""FirstName":"Jean""MiddleName":"P.""LastName":"Handley""CompanyName":"Central Discount Store""RowNumber":14},{"CustomerID":21"Title":"FirstName":"Jinghao""MiddleName":"LastName":"Liu""CompanyName":"Chic Department Stores""RowNumber":15},{"CustomerID":22"Title":"Ms.""FirstName":"Linda""MiddleName":"E.""LastName":"Burnett""CompanyName":"Travel Systems""RowNumber":16},{"CustomerID":23"Title":"Mr.""FirstName":"Kerim""MiddleName":"LastName":"Hanif""CompanyName":"Bike World""RowNumber":17},{"CustomerID":24"Title":"Mr.""FirstName":"Kevin""MiddleName":"LastName":"Liu""CompanyName":"Eastside Department Store""RowNumber":18},{"CustomerID":25"Title":"Mr.""FirstName":"Donald""MiddleName":"L.""LastName":"Blanton""CompanyName":"Coalition Bike Company""RowNumber":19},{"CustomerID":28"Title":"Ms.""FirstName":"Jackie""MiddleName":"E.""LastName":"Blackwell""CompanyName":"Commuter Bicycle Store""RowNumber":20}]}

Here is my C# code that is generating the JSON

sb.Append("{\"rowval\" :");
            sb.Append("[");
            if (table != null)
            {
                foreach (DataRow row in table.Rows)
                {
                    sb.Append("{");
                    if (row.Table != null && row.Table.Columns != null && row.Table.Columns.Count > 0)
                    {
                        foreach (DataColumn column in row.Table.Columns)
                        {
                            parseMember(row[column], column.ColumnName, sb);
                        }
                    }
                    sb.Append("},");
                }
            }
            sb.Append("]");
            sb.Append("}");

            sqlcon.Close();
            Response.Write(sb);



        }

        private static void parseMember(object val, string memberName, StringBuilder sb)
        {
            Type t = val.GetType();

            if (memberName != null && memberName.Trim().Length > 0)
                sb.AppendFormat("\"{0}\":", memberName);
            if (typeof(string) == t || typeof(char) == t)
                sb.AppendFormat("\"{0}\"", val.ToString());
            else
                sb.AppendFormat("{0}", val.ToString());
        }
  • 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-28T05:27:48+00:00Added an answer on May 28, 2026 at 5:27 am

    if you are getting json then specifying dataType equal to json as 4th argument in$.getwill parse the json which you can iterate using theeach` method of jquery, like

     $.get('Dataextract.aspx', function (data, textStatus) {
            alert('Status is ' + textStatus);//success
            alert('JSON data string is: ' + data);//string as below
        // no need for eval
       // var JSONdata = data;
       // eval(JSONdata);//error here-> expected ;
        alert(JSONdata.rowval[0].CustomerID);
    
    }, "json"); // <-- 
    

    or you can parse the json explicitly like

     $.get('Dataextract.aspx', function (data, textStatus) {
            alert('Status is ' + textStatus);//success
            alert('JSON data string is: ' + data);//string as below
    
        var JSONdata = $.parseJSON(data);
       // eval(JSONdata);//error here-> expected ;  again no need for the eval
        alert(JSONdata.rowval[0].CustomerID);
    
    }, 'text');
    

    update

    the json you are forming is not correct, for validating your json you can visit http://www.jsonlint.com, this is the valid json

    {
        "rowval": [
            {
                "CustomerID": 12,  // <-- you are missing the commas 
                "Title": "Mr.",
                "FirstName": "Johnny",
                "MiddleName": "A.",
                "LastName": "Caprio",
                "CompanyName": "Bikes and Motorbikes",
                "RowNumber": 10
            }
        ]
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need store just 10 arrays in my app, which I can change from
I need to store locally on android devices some images I get from the
I need to set up a CheckboxGroup checkboxes with values loaded with json from
I have a set of string that I need to store in a set,
I have id values for products that I need store. Right now they are
I need to store user credentials in my app. I can store and retrieve
I have a set S of small trees S[i] which I need to find
I need to store the result set of a stored procedure in a temporary
I want to pass the string value which I get from the textarea into
I have an array of NSDates which I build from strings using [NSDate dateFromString]

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.