//????FastJson????
static void TestFastJson(int count?? object obj)
{
Stopwatch sw = new Stopwatch();
JSONParameters p = new JSONParameters();
p.EnableAnonymousTypes
= p.IgnoreCaseOnDeserialize
= p.ShowReadOnlyProperties
= p.UseEscapedUnicode
= p.UseExtensions
= p.UseFastGuid
= p.UseOptimizedDatasetSchema
= p.UseUTCDateTime
= p.UsingGlobalTypes
= false;
Console.WriteLine();
Console.WriteLine("fastJSON.NET ???" + count + " ??10??");
for (int j = 0; j < 10; j++)
{
sw.Restart();
for (int i = 0; i < count; i++)
{
fastJSON.JSON.Instance.ToJSON(obj?? p);
}
sw.Stop();
Console.Write(sw.ElapsedMilliseconds + "ms | ");
}
Console.WriteLine();
Console.WriteLine("???:" + fastJSON.JSON.Instance.ToJSON(obj?? p));
Console.WriteLine("==============================================");
}
//????JayrockJson????
static void TestJayrockJson(int count?? object obj)
{
Stopwatch sw = new Stopwatch();
Console.WriteLine();
Console.WriteLine("Jayrock.Json ???" + count + " ??10??");
for (int j = 0; j < 10; j++)
{
sw.Restart();
for (int i = 0; i < count; i++)
{
var writer = new Jayrock.Json.JsonTextWriter();
Jayrock.Json.Conversion.JsonConvert.Export(obj?? writer);
string str = writer.ToString();
}
sw.Stop();
Console.Write(sw.ElapsedMilliseconds + "ms | ");
}
var w = new Jayrock.Json.JsonTextWriter();
Jayrock.Json.Conversion.JsonConvert.Export(obj?? w);
Console.WriteLine();
Console.WriteLine("???:" + w.ToString());
Console.WriteLine("==============================================");
}
static void TestNewtonsoftJson(int count?? object obj)
{
Stopwatch sw = new Stopwatch();
Console.WriteLine();
Console.WriteLine("Newtonsoft.Json ???" + count + " ??10??");
for (int j = 0; j < 10; j++)
{
sw.Restart();
for (int i = 0; i < count; i++)
{
Newtonsoft.Json.JsonConvert.SerializeObject(obj);
}
sw.Stop();
Console.Write(sw.ElapsedMilliseconds + "ms | ");
}
var w = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
Console.WriteLine();
Console.WriteLine("???:" + w.ToString());
Console.WriteLine("==============================================");
}
static void TestJavaScriptSerializer(int count?? object obj)
{
Stopwatch sw = new Stopwatch();
Console.WriteLine();
Console.WriteLine("JavaScriptSerializer ???" + count + " ??10??");
for (int j = 0; j < 10; j++)
{
sw.Restart();
for (int i = 0; i < count; i++)
{
new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(obj);
}
sw.Stop();
Console.Write(sw.ElapsedMilliseconds + "ms | ");
}
var w = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(obj);
Console.WriteLine();
Console.WriteLine("???:" + w.ToString());
Console.WriteLine("==============================================");
}
//????JsonBuilder????
static void JsonBuilder(int count?? object obj)
{
Stopwatch sw = new Stopwatch();
Console.WriteLine();
Console.WriteLine("QuickJsonBuilder ???" + count + " ??10??");
for (int j = 0; j < 10; j++)
{
sw.Reset();
sw.Start();
for (int i = 0; i < count; i++)
{
JsonBuilder jb = new JsonBuilder();
jb.ToJsonString(obj);
}
sw.Stop();
Console.Write(sw.ElapsedMilliseconds + "ms | ");
}
Console.WriteLine();
Console.WriteLine("???:" + new JsonBuilder().ToJsonString(obj));
Console.WriteLine("==============================================");
}
}
}
???????????1??????????? JavaScriptSerializer
?????????????System.Web.Extensions????????????????o??
????string str = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(User.TestUser());
????//{"Self":null??"UID":"6f50b429-5c13-4875-a29a-e4bd8d7b2772"??"Name":"blqw"??"Birthday":"/Date(530964000000)/"??"Sex":0??"IsDeleted":false??"LoginHistory":["/Date(1377129600000)/"??"/Date(1377137410000)/"??"/Date(1377146036000)/"??"/Date(1377163518000)/"??"/Date(1377184019000)/"]??"Info":{"Address":"?????????"??"Phone":{"???":"18688888888"??"?綽":"82580000"??"???":"10086"??"QQ":"21979018"}??"ZipCode":510000}??"Double":-Infinity}
???????????2??Newtonsoft.Json
?????????????Newtonsoft.Json.Net35.dll
????string str = Newtonsoft.Json.JsonConvert.SerializeObject(User.TestUser());
????//{"Self":null??"UID":"6f50b429-5c13-4875-a29a-e4bd8d7b2772"??"Name":"blqw"??"Birthday":"/Date(530964000000+0800)/"??"Sex":0??"IsDeleted":false??"LoginHistory":["/Date(1377129600000+0800)/"??"/Date(1377137410000+0800)/"??"/Date(1377146036000+0800)/"??"/Date(1377163518000+0800)/"??"/Date(1377184019000+0800)/"]??"Info":{"Address":"?????????"??"Phone":{"???":"18688888888"??"?綽":"82580000"??"???":"10086"??"QQ":"21979018"}??"ZipCode":510000}??"Double":-Infinity}
???????????3??Jayrock.Json
?????????????Jayrock.Json.dll
????JsonTextWriter jtw = new Jayrock.Json.JsonTextWriter();
????Jayrock.Json.Conversion.JsonConvert.Export(User.TestUser()?? jtw);
????string str = jtw.ToString();
????//{"uID":"6f50b429-5c13-4875-a29a-e4bd8d7b2772"??"name":"blqw"??"birthday":"1986-10-29T18:00:00.0000000+08:00"??"sex":"Male"??"isDeleted":false??"loginHistory":["2013-08-22T08:00:00.0000000+08:00"??"2013-08-22T10:10:10.0000000+08:00"??"2013-08-22T12:33:56.0000000+08:00"??"2013-08-22T17:25:18.0000000+08:00"??"2013-08-22T23:06:59.0000000+08:00"]??"info":{"address":"?????????"??"phone":{"???":"18688888888"??"?綽":"82580000"??"???":"10086"??"QQ":"21979018"}??"zipCode":510000}??"double":-Infinity}
???????????4??fastJSON.NET
?????????????fastJSON.dll
????JSONParameters p = new JSONParameters();
????p.EnableAnonymousTypes
????= p.IgnoreCaseOnDeserialize
????= p.ShowReadOnlyProperties
????= p.UseEscapedUnicode
????= p.UseExtensions
????= p.UseFastGuid
????= p.UseOptimizedDatasetSchema
????= p.UseUTCDateTime
????= p.UsingGlobalTypes
????= false;//???в????false?????????
????string str = fastJSON.JSON.Instance.ToJSON(User.TestUser()?? p);
????//{"Self":null??"UID":"6f50b429-5c13-4875-a29a-e4bd8d7b2772"??"Name":"blqw"??"Birthday":"1986-10-29 18:00:00"??"Sex":"Male"??"IsDeleted":false??"LoginHistory":["2013-08-22 08:00:00"??"2013-08-22 10:10:10"??"2013-08-22 12:33:56"??"2013-08-22 17:25:18"??"2013-08-22 23:06:59"]??"Info":{"Address":"?????????"??"Phone":{"???":"18688888888"??"?綽":"82580000"??"???":"10086"??"QQ":"21979018"}??"ZipCode":510000}??"Double":-Infinity}
???????????5??6??QuickJsonBuilder??JsonBuilder
????ps:?????????????????????????????У?????????
?????????QuickJsonBuilder????????н????JsonBuilder?????
????QuickJsonBuilder jb = new QuickJsonBuilder();
????jb.ToJson(User.TestUser());
????//{"Self":null??"UID":"6f50b429-5c13-4875-a29a-e4bd8d7b2772"??"Name":"blqw"??"Birthday":"1986-10-29 18:00:00"??"Sex":"Male"??"IsDeleted":false??"LoginHistory":["2013-08-22 08:00:00"??"2013-08-22 10:10:10"??"2013-08-22 12:33:56"??"2013-08-22 17:25:18"??"2013-08-22 23:06:59"]??"Info":{"Address":"?????????"??"Phone":{"???":"18688888888"??"?綽":"82580000"??"???":"10086"??"QQ":"21979018"}??"ZipCode":510000}??"Double":-Infinity}
????ps:??Self???????????????????? "Self":undefined ????????????
???????????7??ServiceStack.Text
?????????????ServiceStack.Text.dll ?????????4.0??
?????????????????????????????????...
????User.TestUser().ToJson();
????//{"UID":"48d4624ad0c8475094d00fc769c7129f"??"Name":"blqw"??"Birthday":"/Date(530964000000+0800)/"??"Sex":"Male"??"IsDeleted":false??"LoginHistory":["/Date(1377129600000+0800)/"??"/Date(1377137410000+0800)/"??"/Date(1377146036000+0800)/"??"/Date(1377163518000+0800)/"??"/Date(1377184019000+0800)/"]??"Info":{"Address":"?????????"??"Phone":{"???":"18688888888"??"?綽":"82580000"??"???":"10086"??"QQ":"21979018"}??"ZipCode":510000}??"Double":-Infinity}
????ps:????????????????????????
??????????(??λ "????")

???????????????ο?
???????
??????????????????????????????????????????????????Щ????????????????
?????????????????????1?ε?????????
????JavaScriptSerializer ?????????100????????????????????Щ????????????????????????????????
????Newtonsoft.Json????????????????????????????JsonBuilder?????????к???????
????Jayrock.Json ???????λ???????????????????sdk?????????????????ò????
????fastJSON.NET ????????????п???QuickJsonBuilder????н?????Щ??????
????ServiceStack.Text ?й??о???Newtonsoft.Json??????.????????4.0????????????????2.0???????????????
?????e? ?????????????????????