JSON & C#
1.System.Text.Json.Utf8JsonReader
ref: https://docs.microsoft.com/en-us/dotnet/core/whats-new/dotnet-core-3-0
https://github.com/ysharplanguage/FastJsonParser#Overview
2. Newtonsoft.Json library
using NewTonsoft.Json; //Using Manage NuGet Packages installs Newtonsoft.Json.
Cat cat2 = new Cat(){name="hik",age=3};
string s1=Newtonsoft.Json.JsonConvert.SerializeObject(cat2);
Cat cat3 = JsonConvert.DeserializeObject<Cat>(JSONstr);
string outStr2 = JsonConvert.SerializeObject(cat2);
private string CapitalFirstLetter(string s)
{
try
{
string rs = char.ToUpper(s[0]) + s.Substring(1);
return rs;
}catch(Exception e) { return s; }
}
3.JavaScriptSerializer
using System.Web.Script.Serialization;
using System.IO;
//Script.Serialization is in System.Web.Extensions.
//We need to add a reference that is System.Web.Extensions in Assemblies in Reference Manager
string JSONstr= File.ReadAllText("JSON.json");
// $"{{\"name\":\"{name1}\",\"age\":1}}"
JavaScriptSerializer ser = new JavaScriptSerializer();
Cat cat1 = ser.Deserialize<Cat>(JSONstr);
Cat cat2 = new Cat(){name="hik",age=3};
string outStr = ser.Serialize(cat2);
File.WriteAllText("Cat.json",outStr);
4 .simdjson : Parsing gigabytes of JSON per second
https://github.com/lemire/simdjson
ref: https://docs.microsoft.com/en-us/dotnet/core/whats-new/dotnet-core-3-0
https://github.com/ysharplanguage/FastJsonParser#Overview
2. Newtonsoft.Json library
using NewTonsoft.Json; //Using Manage NuGet Packages installs Newtonsoft.Json.
Cat cat2 = new Cat(){name="hik",age=3};
string s1=Newtonsoft.Json.JsonConvert.SerializeObject(cat2);
Cat cat3 = JsonConvert.DeserializeObject<Cat>(JSONstr);
string outStr2 = JsonConvert.SerializeObject(cat2);
private string CapitalFirstLetter(string s)
{
try
{
string rs = char.ToUpper(s[0]) + s.Substring(1);
return rs;
}catch(Exception e) { return s; }
}
3.JavaScriptSerializer
using System.Web.Script.Serialization;
using System.IO;
//Script.Serialization is in System.Web.Extensions.
//We need to add a reference that is System.Web.Extensions in Assemblies in Reference Manager
string JSONstr= File.ReadAllText("JSON.json");
// $"{{\"name\":\"{name1}\",\"age\":1}}"
JavaScriptSerializer ser = new JavaScriptSerializer();
Cat cat1 = ser.Deserialize<Cat>(JSONstr);
Cat cat2 = new Cat(){name="hik",age=3};
string outStr = ser.Serialize(cat2);
File.WriteAllText("Cat.json",outStr);
4 .simdjson : Parsing gigabytes of JSON per second
https://github.com/lemire/simdjson
评论
发表评论