示例#1
0
        protected void btnToJson_Click(object sender, EventArgs e)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            Aa aa1 = new Aa {
                A1 = "aa1", A2 = "bb1", A3 = "cc1"
            };

            StringBuilder sb = new StringBuilder(1000);

            sb.Append("{");
            sb.Append("\"A1\":\"");
            sb.Append(aa1.A1);
            sb.Append("\"");

            sb.Append(",\"A2\":\"");
            sb.Append(aa1.A2);
            sb.Append("\"");

            sb.Append(",\"A3\":\"");
            sb.Append(aa1.A3);
            sb.Append("\"");

            sb.Append("}");

            txtJsonMsg.Text += sb.ToString();
            sw.Stop();


            txtJsonMsg.Text += "\n==========================\nStringBuilder用时:" + Functions.TimeSpantoFloat(sw.Elapsed);

            sw.Reset();
            sw.Start();
            Aa aa = new Aa {
                A1 = "aa", A2 = "bb", A3 = "cc"
            };

            //string strJson = JsonConvert.SerializeObject(aa);
            //txtJsonMsg.Text += strJson;

            //sw.Stop();

            //txtJsonMsg.Text += "\n==========================\nJsonConvert用时:" + Functions.TimeSpantoFloat(sw.Elapsed) + "\n";
        }
        protected void btnToJson_Click(object sender, EventArgs e)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            Aa aa1 = new Aa { A1 = "aa1", A2 = "bb1", A3 = "cc1" };

            StringBuilder sb = new StringBuilder(1000);
            sb.Append("{");
            sb.Append("\"A1\":\"");
            sb.Append(aa1.A1);
            sb.Append("\"");

            sb.Append(",\"A2\":\"");
            sb.Append(aa1.A2);
            sb.Append("\"");

            sb.Append(",\"A3\":\"");
            sb.Append(aa1.A3);
            sb.Append("\"");

            sb.Append("}");

            txtJsonMsg.Text += sb.ToString();
            sw.Stop();

         
            txtJsonMsg.Text += "\n==========================\nStringBuilder用时:" + Functions.TimeSpantoFloat(sw.Elapsed);

            sw.Reset();
            sw.Start();
            Aa aa = new Aa {A1 = "aa",A2= "bb",A3="cc"};

            //string strJson = JsonConvert.SerializeObject(aa);
            //txtJsonMsg.Text += strJson;

            //sw.Stop();

            //txtJsonMsg.Text += "\n==========================\nJsonConvert用时:" + Functions.TimeSpantoFloat(sw.Elapsed) + "\n";

            
        }