Return Json string from C# and display it in Textbox using javascript and jquery
<p>Display data values in text box. I'm generating a JSON string from datatable in C#.I need to display it in text boxes using Javascript. I've tried with following method but it's displaying empty values. seems like I missed something in my code. Here is my code</p>

<p><div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;

&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head runat="server"&gt;
    &lt;title&gt;&lt;/title&gt;
    &lt;script src="Scripts/jquery-1.12.1.min.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script src="Scripts/jquery-2.2.1.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script type="text/javascript"&gt;
        function initialize() {
            var data = JSON.parse('&lt;%=ConvertDataTabletoString() %&gt;');//returns "[{\"TAG1\":100,\"TAG2\":100}]"
            if (data.var1) {
                $('#TextBox1').val(data[0].TAG1);
            }
            if (data.var2) {
                $('#TextBox1').val(data[0].TAG2);
            }
        }
    &lt;/script&gt;
&lt;/head&gt;
&lt;body onload="initialize()"&gt;
    &lt;form id="form1" runat="server"&gt;
        &lt;div&gt;
            &lt;asp:TextBox ID="TextBox1" runat="server"&gt;&lt;/asp:TextBox&gt;
            &lt;asp:TextBox ID="TextBox2" runat="server"&gt;&lt;/asp:TextBox&gt;

        &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</code></pre>
</div>
</div>
</p>

<p>and my code behind</p>

<pre><code>public string ConvertDataTabletoString()
{
    string strcon = ConfigurationManager.ConnectionStrings["SqlCon"].ConnectionString;
    DataTable dt = new DataTable();
    using (SqlConnection con = new SqlConnection(strcon))
    {
        using (SqlCommand cmd = new SqlCommand("SELECT TOP 1 TAG1,TAG2 FROM DATATABLE1  ORDER BY 1 DESC", con))
        {
            con.Open();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(dt);
            System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            List&lt;Dictionary&lt;string, object&gt;&gt; rows = new List&lt;Dictionary&lt;string, object&gt;&gt;();
            Dictionary&lt;string, object&gt; row;
            foreach (DataRow dr in dt.Rows)
            {
                row = new Dictionary&lt;string, object&gt;();
                foreach (DataColumn col in dt.Columns)
                {
                    row.Add(col.ColumnName, dr[col]);
                }
                rows.Add(row);
            }

            return serializer.Serialize(rows); //returns JSON string "[{\"TAG1\":100,\"TAG2\":100}]"
        }
    }
}
</code></pre>

<p>I tried this also.</p>

<blockquote>
  <p><strong>$('#TextBox1').val(data.TAG1);</strong></p>
</blockquote>