Azrng.Core.NewtonsoftJson
1.3.1
dotnet add package Azrng.Core.NewtonsoftJson --version 1.3.1
NuGet\Install-Package Azrng.Core.NewtonsoftJson -Version 1.3.1
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="Azrng.Core.NewtonsoftJson" Version="1.3.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Azrng.Core.NewtonsoftJson" Version="1.3.1" />
<PackageReference Include="Azrng.Core.NewtonsoftJson" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Azrng.Core.NewtonsoftJson --version 1.3.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Azrng.Core.NewtonsoftJson, 1.3.1"
#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.
#:package Azrng.Core.NewtonsoftJson@1.3.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Azrng.Core.NewtonsoftJson&version=1.3.1
#tool nuget:?package=Azrng.Core.NewtonsoftJson&version=1.3.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Azrng.Core.NewtonsoftJson
这是一个基于 Newtonsoft.Json 封装的 JSON 序列化库,提供了常用的 JSON 序列化和反序列化功能。
功能特性
- 基于成熟的 Newtonsoft.Json 库
- 支持多框架:.NET 6.0 / 7.0 / 8.0 / 9.0 / 10.0
- 内置常用 JSON 转换器
- 支持自定义序列化配置
- 提供对象深拷贝功能
- 默认使用 CamelCase 命名策略
- 默认时间格式为 "yyyy-MM-dd HH:mm:ss"
安装
通过 NuGet 安装:
Install-Package Azrng.Core.NewtonsoftJson
或通过 .NET CLI:
dotnet add package Azrng.Core.NewtonsoftJson
使用方法
基本配置
在 Program.cs 或 Startup.cs 中注册服务:
// 基本配置
services.ConfigureNewtonsoftJson();
// 自定义配置
services.ConfigureNewtonsoftJson(options =>
{
// 自定义序列化选项
options.JsonSerializeOptions.Formatting = Formatting.Indented;
options.JsonDeserializeOptions.DateFormatString = "yyyy-MM-dd";
});
在服务中使用
注入 IJsonSerializer 接口并在代码中使用:
public class MyService
{
private readonly IJsonSerializer _jsonSerializer;
public MyService(IJsonSerializer jsonSerializer)
{
_jsonSerializer = jsonSerializer;
}
public void DoSomething()
{
var obj = new MyObject { Name = "test" };
// 序列化对象
string json = _jsonSerializer.ToJson(obj);
// 反序列化对象
var deserializedObj = _jsonSerializer.ToObject<MyObject>(json);
// 对象深拷贝
var clonedObj = _jsonSerializer.Clone(obj);
// 反序列化为列表
var list = _jsonSerializer.ToList<MyObject>("[{\"Name\":\"item1\"},{\"Name\":\"item2\"}]");
}
}
静态工具方法
除了通过依赖注入使用外,还提供了部分静态帮助类用于便利操作:
using Azrng.Core.NewtonsoftJson.Utils;
// JSON 转列表
var list = JsonHelper.ToList<MyObject>("[{\"Name\":\"item1\"},{\"Name\":\"item2\"}]");
// 验证 JSON 格式
bool isValid = JsonHelper.IsJsonString(json);
bool isArray = JsonHelper.IsJArrayString(json);
注意:其他序列化操作(如对象转 JSON、JSON 转对象、对象深拷贝)建议使用依赖注入的 IJsonSerializer 接口,以获得更好的可维护性和一致性。
该库包含以下内置转换器:
- LongToStringConverter - 长整型与字符串互转
可以通过自定义配置添加这些转换器:
services.ConfigureNewtonsoftJson(options =>
{
options.JsonSerializeOptions.Converters.Add(new LongToStringConverter());
options.JsonDeserializeOptions.Converters.Add(new LongToStringConverter());
});
依赖包
- Azrng.Core
- Newtonsoft.Json
版本更新记录
- 1.3.1
- 更新包引用
- 1.3.0
- 更新JsonHelper方法
- 1.2.6
- 发布正式版
- 1.2.6-beta2
- 引用.Net10正式包
- 1.2.6-beta1
- 适配.Net10
- 1.2.5
- 更新扩展方法Clone为JsonHelper的静态方法
- 1.2.4
- 修复包引用问题
- 1.2.3
- 更新ObjectExtensions到ObjectCopyExtensions
- 1.2.2
- 修复包引用问题
- 1.2.1
- 修复ToJson报错问题
- 1.2.0
- 更新IJsonSerializer中ToJson泛型约束
- 1.1.1
- 修复null值情况下反序列化报错的问题
- 1.1.0
- 更新引用包
- 1.0.0
- 基础的序列化包
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 is compatible. 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 is compatible. 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. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Azrng.Core (>= 1.8.4)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
- Newtonsoft.Json (>= 13.0.3)
-
net6.0
- Azrng.Core (>= 1.8.4)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Options (>= 6.0.0)
- Newtonsoft.Json (>= 13.0.3)
-
net7.0
- Azrng.Core (>= 1.8.4)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
- Microsoft.Extensions.Options (>= 7.0.0)
- Newtonsoft.Json (>= 13.0.3)
-
net8.0
- Azrng.Core (>= 1.8.4)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
- Newtonsoft.Json (>= 13.0.3)
-
net9.0
- Azrng.Core (>= 1.8.4)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Options (>= 9.0.0)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Azrng.Core.NewtonsoftJson:
| Package | Downloads |
|---|---|
|
AzrngCommon
基本的公共类库 |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.3.1 | 87 | 3/2/2026 |
| 1.3.0 | 118 | 1/26/2026 |
| 1.2.6 | 602 | 12/1/2025 |
| 1.2.6-beta2 | 292 | 11/12/2025 |
| 1.2.6-beta1 | 174 | 11/6/2025 |
| 1.2.5 | 195 | 10/25/2025 |
| 1.2.4 | 243 | 10/13/2025 |
| 1.2.3 | 195 | 10/13/2025 |
| 1.2.2 | 201 | 10/8/2025 |
| 1.2.1 | 203 | 10/8/2025 |
| 1.2.0 | 340 | 9/18/2025 |
| 1.1.1 | 325 | 8/26/2025 |
| 1.1.0 | 420 | 3/20/2025 |
| 1.0.0 | 227 | 3/18/2025 |