-Documentation
-Performance
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation
|
||||
{
|
||||
public class JsonNetVsWindowsDataJsonTests
|
||||
{
|
||||
public void CreatingJson()
|
||||
{
|
||||
#if NETFX_CORE
|
||||
#region CreatingJSON
|
||||
// Windows.Data.Json
|
||||
// -----------------
|
||||
JsonObject jsonObject = new JsonObject
|
||||
{
|
||||
{"CPU", JsonValue.CreateStringValue("Intel")},
|
||||
{
|
||||
"Drives", new JsonArray
|
||||
{
|
||||
JsonValue.CreateStringValue("DVD read/writer"),
|
||||
JsonValue.CreateStringValue("500 gigabyte hard drive")
|
||||
}
|
||||
}
|
||||
};
|
||||
string json1 = jsonObject.Stringify();
|
||||
|
||||
// LINQ to JSON
|
||||
// ------------
|
||||
JObject jObject = new JObject
|
||||
{
|
||||
{"CPU", "Intel"},
|
||||
{
|
||||
"Drives", new JArray
|
||||
{
|
||||
"DVD read/writer",
|
||||
"500 gigabyte hard drive"
|
||||
}
|
||||
}
|
||||
};
|
||||
string json2 = jObject.ToString();
|
||||
#endregion
|
||||
#endif
|
||||
}
|
||||
|
||||
public void QueryingJson()
|
||||
{
|
||||
#if NETFX_CORE
|
||||
#region QueryingJSON
|
||||
string json = @"{
|
||||
'channel': {
|
||||
'title': 'James Newton-King',
|
||||
'link': 'http://james.newtonking.com',
|
||||
'description': 'James Newton-King's blog.',
|
||||
'item': [
|
||||
{
|
||||
'title': 'Json.NET 1.3 + New license + Now on CodePlex',
|
||||
'description': 'Annoucing the release of Json.NET 1.3, the MIT license and the source being available on CodePlex',
|
||||
'link': 'http://james.newtonking.com/projects/json-net.aspx',
|
||||
'category': [
|
||||
'Json.NET',
|
||||
'CodePlex'
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}";
|
||||
|
||||
// Windows.Data.Json
|
||||
// -----------------
|
||||
JsonObject jsonObject = JsonObject.Parse(json);
|
||||
string itemTitle1 = jsonObject["channel"].GetObject()["item"].GetArray()[0].GetObject()["title"].GetString();
|
||||
|
||||
// LINQ to JSON
|
||||
// ------------
|
||||
JObject jObject = JObject.Parse(json);
|
||||
string itemTitle2 = (string)jObject["channel"]["item"][0]["title"];
|
||||
#endregion
|
||||
#endif
|
||||
}
|
||||
|
||||
public void Converting()
|
||||
{
|
||||
#if NETFX_CORE
|
||||
#region Converting
|
||||
JsonObject jsonObject = new JsonObject
|
||||
{
|
||||
{"CPU", JsonValue.CreateStringValue("Intel")},
|
||||
{"Drives", new JsonArray {
|
||||
JsonValue.CreateStringValue("DVD read/writer"),
|
||||
JsonValue.CreateStringValue("500 gigabyte hard drive")
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// convert Windows.Data.Json to LINQ to JSON
|
||||
JObject o = JObject.FromObject(jsonObject);
|
||||
|
||||
// convert LINQ to JSON to Windows.Data.Json
|
||||
JArray a = (JArray)o["Drives"];
|
||||
JsonArray jsonArray = a.ToObject<JsonArray>();
|
||||
#endregion
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -713,6 +713,7 @@ _____'propertyName': NaN
|
||||
jsonWriter.WriteValue(data);
|
||||
jsonWriter.WriteValue((object)data);
|
||||
jsonWriter.WriteValue((byte[])null);
|
||||
jsonWriter.WriteValue((Uri)null);
|
||||
jsonWriter.WriteEndArray();
|
||||
}
|
||||
|
||||
@@ -720,6 +721,7 @@ _____'propertyName': NaN
|
||||
""SGVsbG8gd29ybGQu"",
|
||||
""SGVsbG8gd29ybGQu"",
|
||||
""SGVsbG8gd29ybGQu"",
|
||||
null,
|
||||
null
|
||||
]";
|
||||
string result = sb.ToString();
|
||||
|
||||
@@ -64,8 +64,8 @@ namespace Newtonsoft.Json.Tests
|
||||
[TestFixture]
|
||||
public class PerformanceTests : TestFixtureBase
|
||||
{
|
||||
private const int Iterations = 100;
|
||||
//private const int Iterations = 5000;
|
||||
//private const int Iterations = 100;
|
||||
private const int Iterations = 5000;
|
||||
|
||||
#region Data
|
||||
|
||||
@@ -122,21 +122,19 @@ namespace Newtonsoft.Json.Tests
|
||||
TestClass test = CreateSerializationObject();
|
||||
|
||||
SerializeTests(test);
|
||||
|
||||
Deserialize();
|
||||
}
|
||||
|
||||
private void SerializeTests(object value)
|
||||
{
|
||||
BenchmarkSerializeMethod(SerializeMethod.DataContractSerializer, value);
|
||||
BenchmarkSerializeMethod(SerializeMethod.BinaryFormatter, value);
|
||||
BenchmarkSerializeMethod(SerializeMethod.JavaScriptSerializer, value);
|
||||
BenchmarkSerializeMethod(SerializeMethod.DataContractJsonSerializer, value);
|
||||
BenchmarkSerializeMethod(SerializeMethod.JsonNet, value);
|
||||
BenchmarkSerializeMethod(SerializeMethod.JsonNetLinq, value);
|
||||
//BenchmarkSerializeMethod(SerializeMethod.DataContractSerializer, value);
|
||||
//BenchmarkSerializeMethod(SerializeMethod.BinaryFormatter, value);
|
||||
//BenchmarkSerializeMethod(SerializeMethod.JavaScriptSerializer, value);
|
||||
//BenchmarkSerializeMethod(SerializeMethod.DataContractJsonSerializer, value);
|
||||
//BenchmarkSerializeMethod(SerializeMethod.JsonNet, value);
|
||||
//BenchmarkSerializeMethod(SerializeMethod.JsonNetLinq, value);
|
||||
BenchmarkSerializeMethod(SerializeMethod.JsonNetManual, value);
|
||||
BenchmarkSerializeMethod(SerializeMethod.JsonNetWithIsoConverter, value);
|
||||
BenchmarkSerializeMethod(SerializeMethod.JsonNetBinary, value);
|
||||
//BenchmarkSerializeMethod(SerializeMethod.JsonNetWithIsoConverter, value);
|
||||
//BenchmarkSerializeMethod(SerializeMethod.JsonNetBinary, value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -76,5 +76,5 @@ using System.Security;
|
||||
// by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("4.5.0.0")]
|
||||
#if !PocketPC
|
||||
[assembly: AssemblyFileVersion("4.5.10.15431")]
|
||||
[assembly: AssemblyFileVersion("4.5.10.15501")]
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user