EleCho.Json 1.0.2

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package EleCho.Json --version 1.0.2
NuGet\Install-Package EleCho.Json -Version 1.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EleCho.Json" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EleCho.Json --version 1.0.2
#r "nuget: EleCho.Json, 1.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install EleCho.Json as a Cake Addin
#addin nuget:?package=EleCho.Json&version=1.0.2

// Install EleCho.Json as a Cake Tool
#tool nuget:?package=EleCho.Json&version=1.0.2

EleCho.Json

nuget nuget github last commit gitHub code size in bytes

Easy, Simple and Fast JSON reader and writer. You can also use model class to operate JSON data. 便捷, 简单以及高速的 JSON 读写器. 同时以也可以使用实体类来操作 JSON 数据.

The document is available in English and Chinese, just scroll down. 文档有英文和中文, 往下翻阅即可.

English

This library is primarily for simple JSON operations that are fast and don't require complex features, such as primitive type conversions.

Various JSON object stores

JsonObject jObj = new JsonObject();    // JSON Object (Key-value pair storage)
jObj.Add("some_key", "any_value");     // Set value with string key
jObj["some_key"] = new JsonString("Some string value");   // Set key with "this[...]", assign with IJsonData

JsonArray jArr = new JsonArray();      // JSON Array (List storage)
jArr.Add("Any value");                 // Add any JSON data.
jArr.Add(new JsonString("Anything"));  // Or use JsonString

JsonString jStr = "QWQ";               // Create JSON string with implicit type conversion
JsonBoolean jBl = true;                // Create JSON boolean with implicit type conversion
JsonNull = new JsonNull();       // JSON null, or use JsonData.Null

// Read JSON data:
string someStr = jObj["some_key"] as JsonString;   // Read JSON string from JSON object.
int someNum = jObj["some_key_num"] as JsonNumber;  // Read JSON number from JSON object.

Write JSON data to stream

Stream stream;  // 要写入的 Stream
IJsonData someJsonData;
JsonWriter jw = new JsonWriter(stream);
jw.Write(someJsonData);

Read JSON data from stream

Stream stream;  // 要读取的 Stream
JsonReader jr = new JsonReader(stream);   // 实例化 JSON 读取器
IJsonData jsonData = jr.Read();           // 从流中读取一个完整的 JSON 数据

Create JSON data with any object

IJsonData jsonData = JsonData.FromValue(new()
{
    Name = "SlimeNull",
    Age = 18,
    Description = "CSharper! love .NET (*/ω\*)"
});

Create model object with JSON data

class One
{
    public string Name;
    public int Age;
    public string Description;

    // you can also use Property here
}

void LogicalCode()
{
    JsonObject someJsonData;   // JSON data to process
    One model = JsonData.ToValue(typeof(One), someJsonData);
}

Serialize model object to JSON string

class One
{
    public string Name;
    public int Age;
    public string Description;
}

void LogicalCode()
{
    One model = new One() { Name = "SlimeNull", Age = 18, Description = "Some text" };
    string jsonText = JsonSerializer.Serialize(model);
}

Deserialize from JSON string

class One
{
    public string Name;
    public int Age;
    public string Description;
}

void LogicalCode()
{
    string jsonTxt;
    One model = JsonSerializer.Deserialize<One>(jsonTxt);
}

Parse JSON tokens from stream

Stream stream;     // Stream to read
JsonLexer jLexer = new JsonLexer(stream);
jLexer.PeekToken();   // peek a token from the stream
jLexer.ReadToken();   // read a token from the stream

简体中文

这个库主要是追求较高速率的, 不要求复杂特性的简易 JSON 操作, 例如最基本类型的转换.

各种 JSON 对象存储

JsonObject jObj = new JsonObject();    // JSON 对象 (键值对存储)
jObj.Add("some_key", "any_value");     // 使用字符串键设置值
jObj["some_key"] = new JsonString("Some string value");   // 或者使用 "this[...]" 和 IJsonData 设置

JsonArray jArr = new JsonArray();      // JSON 数组 (列表存储)
jArr.Add("Any value");                 // 添加任何 JSON 数据
jArr.Add(new JsonString("Anything"));  // 或者使用 JsonString

JsonString jStr = "QWQ";               // 使用隐式类型转换创建 JSON 字符串
JsonNumber jNum = 114514;              // 床架 JSON 数字 (它使用 double 存储)
JsonBoolean jBl = true;                // 创建 JSON 逻辑值(布尔值)
JsonNull = new JsonNull();             // JSON null, 或者使用 JsonData.Null

// Read JSON data:
string someStr = jObj["some_key"] as JsonString;   // 从 JSON 对象中读取 JSON 字符串
int someNum = jObj["some_key_num"] as JsonNumber;  // 从 JSON 对象中读取 JSON 数字

将 JSON 数据写入到流

Stream stream;  // 要写入的 Stream
IJsonData someJsonData;
JsonWriter jw = new JsonWriter(stream);
jw.Write(someJsonData);

从流中读取 IJsonData:

Stream stream;  // 要读取的 Stream
JsonReader jr = new JsonReader(stream);   // 实例化 JSON 读取器
IJsonData jsonData = jr.Read();           // 从流中读取一个完整的 JSON 数据

从任意创建 JSON 数据

IJsonData jsonData = JsonData.FromValue(new()
{
    Name = "SlimeNull",
    Age = 18,
    Description = "CSharper! love .NET (*/ω\*)"
});

从 JSON 数据创建模型对象

class One
{
    public string Name;
    public int Age;
    public string Description;

    // 在这里你也可以使用属性
}

void LogicalCode()
{
    JsonObject someJsonData;   // 要处理的 JSON 数据
    One model = JsonData.ToValue(typeof(One), someJsonData);
}

将对象序列化为 JSON 字符串

class One
{
    public string Name;
    public int Age;
    public string Description;
}

void LogicalCode()
{
    One model = new One() { Name = "SlimeNull", Age = 18, Description = "Some text" };
    string jsonText = JsonSerializer.Serialize(model);
}

从 JSON 字符串反序列化

class One
{
    public string Name;
    public int Age;
    public string Description;
}

void LogicalCode()
{
    string jsonTxt;
    One model = JsonSerializer.Deserialize<One>(jsonTxt);
}

从流中解析 JSON token

Stream stream;     // 要读取的流
JsonLexer jLexer = new JsonLexer(stream);
jLexer.PeekToken();   // 从流中读取一个 token, 但不变更当前的读取状态
jLexer.ReadToken();   // 从流中读取一个 token, 并移动到下一个 token
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
.NET Framework net46 is compatible.  net461 was computed.  net462 was computed.  net463 was computed.  net47 is compatible.  net471 was computed.  net472 was computed.  net48 is compatible.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.6

    • No dependencies.
  • .NETFramework 4.7

    • No dependencies.
  • .NETFramework 4.8

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net5.0

    • No dependencies.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.2 418 8/11/2022
1.2.1 379 8/10/2022
1.2.0 365 8/10/2022
1.1.1 419 4/18/2022
1.0.2 392 4/17/2022
1.0.1 366 4/2/2022
1.0.0 360 3/26/2022