mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-09-19 18:22:24 +08:00
docs: 完善文档
This commit is contained in:
@@ -2,49 +2,12 @@
|
||||
|
||||
---
|
||||
|
||||
> 请先自行阅读:
|
||||
>
|
||||
> [《Microsoft Docs - .NET 中的 JSON 序列化和反序列化(封送和拆收)》](https://docs.microsoft.com/zh-cn/dotnet/standard/serialization/system-text-json-overview)
|
||||
本功能来自于公共组件,请参阅公共组件下的相关文档:
|
||||
|
||||
默认情况下,本库使用 `System.Text.Json` 作为 JSON 序列化器。
|
||||
> [《SKIT.FlurlHttpClient FAQ:如何指定 JSON 序列化器?》](https://github.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient/blob/main/docs/FAQ_JsonSerializer.md)
|
||||
|
||||
如果你更习惯于 `Newtonsoft.Json`,那么你可以在构造得到 `WechatApiClient` 对象后:
|
||||
---
|
||||
|
||||
```csharp
|
||||
client.Configure(settings =>
|
||||
{
|
||||
settings.JsonSerializer = new FlurlNewtonsoftJsonSerializer();
|
||||
});
|
||||
```
|
||||
### 镜像站点
|
||||
|
||||
此外,如果你希望调整一些序列化器的配置项,那么可以:
|
||||
|
||||
```csharp
|
||||
using System.Text.Json;
|
||||
using SKIT.FlurlHttpClient;
|
||||
using SKIT.FlurlHttpClient.Wechat;
|
||||
|
||||
client.Configure(settings =>
|
||||
{
|
||||
var jsonOptions = FlurlSystemTextJsonSerializer.GetDefaultSerializerOptions();
|
||||
jsonOptions.WriteIndented = true;
|
||||
settings.JsonSerializer = new FlurlSystemTextJsonSerializer(jsonOptions);
|
||||
});
|
||||
```
|
||||
|
||||
使用 `Newtonsoft.Json` 时也是同样的:
|
||||
|
||||
```csharp
|
||||
using Newtonsoft.Json;
|
||||
using SKIT.FlurlHttpClient;
|
||||
using SKIT.FlurlHttpClient.Wechat;
|
||||
|
||||
client.Configure(settings =>
|
||||
{
|
||||
var jsonSettings = FlurlNewtonsoftJsonSerializer.GetDefaultSerializerSettings();
|
||||
jsonSettings.Formatting = Formatting.Indented;
|
||||
settings.JsonSerializer = new FlurlNewtonsoftJsonSerializer(jsonSettings);
|
||||
});
|
||||
```
|
||||
|
||||
需要注意的是,虽然你也可在代码中指定成其他实现 `ISerializer` 的 JSON 序列化器,但因本库的接口模型定义与实际发送的 JSON 数据并非完全一致,使用其他实现会导致意外的执行结果,所以请务必只使用本库内置的这两种 JSON 序列化器。
|
||||
国内用户如访问 GitHub 网络状况不佳,可在打开上述链接后,手动将域名部分的 **github.com** 替换为 **gitee.com**、剩余路径部分保持不变,即可访问。
|
||||
|
Reference in New Issue
Block a user