强制 Blazor webassembly 在客户端使用 Newtonsoft.Json

Enforcing Blazor webassembly to use Newtonsoft.Json on client side

在 Blazor webassembly 中有没有一种方法可以强制使用 Newtonsoft.Json 序列化 httpclient 和方法,例如 GetJsonAsync、PostAsJsonAsync 等

或者唯一的方法是编写辅助方法并使用 GetAsync,然后使用 Newtonsoft.Json 手动序列化响应?

is there a way to enforce the use of Newtonsoft.Json for ... PostAsJsonAsync etc.

没有。最近这种情况有所改变,尤其是对于 Blazor。但是 System.Net.Http.Json.HttpClientJsonExtensions 现在直接依赖于 System.Text.Json,不可插入。

所以是的,您将不得不编写自己的助手,这没什么大不了的。链接器甚至可能会删除发布版本中的 System.Text.Json 类,我不确定。

但反问当然是你为什么需要这个? NewtonSoft 从现在开始就是遗留问题,如果您确实有不兼容的数据,可能会询问是否可以使用一些 System.Text 选项来解决这个问题。