Converting string builder to json string
<p>I want get data from a SQL Server database using C#. I am trying to get a json string from string builder. I try like this:</p>

<pre><code>public string GetData()
{
    using (SqlConnection con = new SqlConnection(this.Connection))
    {
        con.Open();

        SqlCommand command = new SqlCommand("Select TITLE, DURATION, STATUS, TYPE from PROJECTS ", con);

        StringBuilder sb = new StringBuilder();
        sb.Append("{");

        using (SqlDataReader reader = command.ExecuteReader())
        {
            while (reader.Read())
            {
                var k = reader.GetString(3);

                if (k == "M")
                {
                    sb.Append("main");
                    sb.Append("{");
                    sb.Append("sub:[]");
                    sb.Append("Tittle:");
                    sb.AppendFormat("{0}", reader["TITTLE"]);
                }

                if (k == "S")
                {
                    sb.Append("sub");
                    sb.Append("{");
                    sb.Append("task:[]");
                    sb.Append("Tittle:");
                    sb.AppendFormat("{0}", reader["TITTLE"]);
                }

                if (k == "T")
                {
                    sb.Append("task");
                    sb.Append("{");
                    sb.Append("Tittle:");
                    sb.AppendFormat("{0}", reader["TITTLE"]);
                }
            };
        }

        sb.Append("}");
        sb.AppendLine();

        return sb.ToString();
    }
}
</code></pre>

<p>Now I get the string like </p>

<pre><code>sb = {{main{sub:[]Tittle:newsub{task:[]Tittle:new1task{Tittle:new2}
</code></pre>

<p>but my required string is like:</p>

<pre><code>[{"main":{"sub":[{"task":[{"tittle":"new2""}],"tittle":"new1","}],"tittle":"new","}}]
</code></pre>

<p>means: my main title is new and sub tittle new1 and task title new2. What change do I need to do to my code to get my required json string??</p>