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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:59:17+00:00 2026-06-11T06:59:17+00:00

I have a Javascript object like this: var jsonDataActual = { source: [{ name:

  • 0

I have a Javascript object like this:

var jsonDataActual = { 
                       "source": [{
                                    "name": "testCaption0", 
                                    "desc": "testDescrip0", 
                                    "values": [{ 
                                                 "from": "/Date(1338811241074)/", 
                                                   "to": "/Date(1346760041074)/", 
                                                "label": "testLabel0", 
                                          "customClass": "GanttRed"
                                               }] 
                                 }], 
                       "navigate": "scroll", 
                        "scale": "weeks", 
                        "maxScale": "months", 
                        "minScale": "days", 
                    "itemsPerPage": 11, 
                     "onItemClick": function (data) { }, 
                      "onAddClick": function (dt, rowId) { } 

                 };

it works fine for me. Now, because of my requirement and need, am making this entire object(including braces i.e.{ } and semicolon 😉 as a string on server side (C#) and returning it to an ajax call (web Method) using a server side method:

in the server side method I do something like this:

return  new JavaScriptSerializer().Serialize(jsonData);

but now this entire returned data (inside Success: function(msg){ var s=msg.d} ) is treated as string, hence it doesn’t work.

I tried these:

  1. var obj = eval('{' + msg.d +'}'); (removing beginning and ending braces in msg.d)
         typeof(obj) is string. failed

  2. eval('var obj ='+msg.d);  (including beginning and ending braces in msg.d)
         typeof(obj) is string. failed

  3. var obj= jQuery.parseJson(msg.d);
        typeof(obj) is string. failed
  4. var obj = new Object();
     //var obj = {}; 
      obj=jQuery.parseJson(msg.d).
      typeof(obj) is string. failed.

please help. How can I convert a server side returned json into object?

Why not is it working for me??. Is it because of structure of my json object??

and why does jsonDataActual works for me but not when sent as a string???

I saw this and this..

Please Help…..

  • 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-06-11T06:59:19+00:00Added an answer on June 11, 2026 at 6:59 am

    found out solution to my specific problem.

    I was constructing a string variable with my json data as its value. And then I would return this string to the client side function(the one making ajax request). i.e.

    Server side method

    [WebMethod]
    public static string GetJsonData()
    {
        string jsonData = String.Empty;
        foreach(var dataItem in objEntireData.Items)
        {
             //  jsonData +=  
        }
       return new JavaScriptSerializer().Serialize(result);
    } 
    

    but it was not working. So instead of constructing a string variable and serializing it, I wrote a class with specific structure and sent it in the return statement(after serialzing).

    i.e. see below classes

        public class A
        {
            public A()
            {
                Values = new List<B>();
            }
            public string prop1 {get; set;}
            public List<B> Values { get; set; }
        }
        public class B
        {
            public string prop2 { get; set; }
            public string prop3 { get; set; }
        }
    

    and I would use this class as below:

    [WebMethod]
    public static string GetJsonData()
    {
              List<A> objA = new List<A>();
              A objAItem = new A();
              foreach (var dbItem in objDataBaseValues)
              {
                    objA.prop1 = "test";
                    B objBItem = new B();
                    b.prop2="value";
                    b.prop3="value";
                    objA.Values.Add(objBItem);
              }
            return new JavaScriptSerializer().Serialize(objA);
    
      }
    

    wrapping up my entire data into a class structure and then serializing this worked for me. my client side function successfully recognized it as an object i.e.

     $.ajax({
                        type: "POST",
                        url: "ProjectGanttChart.aspx/getData",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (msg) {
                            var jsonData = jQuery.parseJSON(msg.d);
                            populateGantt(jsonData);
                         }
              }); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I have a JavaScript object like this: var member = { mother: {
I have a JavaScript object that looks something like this: var myTextOptions = {
I have javascript object defined like this: function SocialMiner() { var verbose=true; var profileArray=new
Possible Duplicate: Dynamic object property name I have an object like this var localAppConfig
I have a javascript object that looks somthing like this: var obj = {
If I have a javascript object/assoc. array defined like this: function somefunction(options) { var
I have a javascript object that looks like this, var telephones = { /*
I have a Javascript object like this: var count = { table:19, people:39, places_details:84,
I have a javascript object like this var obj={ a:{x: someValue, y:anotherValue}, b:{x: bValue,
Suppose I have a javascript object like this: window.config config.UI = { opacity: {

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.