title: Convert C# String into Javascript Object/JSON
body: <p>I have a Javascript object like this:</p>
  
  <pre><code>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) { } 
  
                   };
  </code></pre>
  
  <p>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:</p>
  
  <p>in the server side method I do something like this:</p>
  
  <pre><code>return  new JavaScriptSerializer().Serialize(jsonData);
  </code></pre>
  
  <p>but now this entire returned data (inside <code>Success: function(msg){ var s=msg.d}</code> ) is treated as string, hence it doesn't work.</p>
  
  <p>I tried these:</p>
  
  <pre><code>  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.
  </code></pre>
  
  <p>please help. How can I convert a server side returned json into object? </p>
  
  <p>Why not is it working for me??. Is it because of structure of my json object??</p>
  
  <p>and why does <code>jsonDataActual</code> works for me but not when sent as a string???</p>
  
  <p>I saw <a href="https://stackoverflow.com/questions/1086404/string-to-object-in-js">this</a> and <a href="https://stackoverflow.com/questions/9036429/convert-object-string-to-json">this</a>..</p>
  
  <p>Please Help.....</p>