- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
如果我在我的项目中使用相同的设置,我可以实例化我的 JsonSerializerSettings
的单个静态副本并在整个过程中使用它吗?
例如:
private static readonly JsonSerializerSettings settings = new JsonSerializerSettings {
Formatting = Formatting.Indented,
TypeNameHandling = TypeNameHandling.None,
DateFormatHandling = DateFormatHandling.IsoDateFormat,
TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple
};
public static string ToJSONString(this Object source) {
return JsonConvert.SerializeObject(source, settings);
}
那么,我的线程危险吗?
最佳答案
以下对话发生在推特上,@JamesNK 是 JSON.net 的作者:https://twitter.com/jonathan_oliver/status/332227095616966656
From: Jonathan Oliver @jonathan_oliver To: @JamesNK
Are the static JsonConvert.DeserializeObject methods thread safe? Getting some strange errors using 5.0.4 and 5.0.5.
响应:
James Newton-King ♔ @JamesNK 8 May 2013 @jonathan_oliver
Yes. Create an issue on GitHub if they’re not
响应:
Jonathan Oliver @jonathan_oliver 9 May 2013
@JamesNK It turns out a ContractResolver attached to a static JsonSerializerSettings object I used with JsonConvert wasn't thread safe.
我没有看到曾经提交过错误,但这确实暗示它们的设计应该是线程安全的,但可能存在特定于实现的方法来破坏它,或者它可能不是一个整体。
关于c# - JsonSerializerSettings 线程安全吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23170918/
这个问题在这里已经有了答案: Supporting multiple custom DateTime formats when deserializing with Json.Net (2 个回答)
我想为 DateTime 使用不同的格式关于查询字符串参数的字段:即如果查询字符串包含 dateFormat=iso参数,我想返回 ISO 6801 中的日期: { "date": "2018-0
我尝试实现来自 Newtonsoft Documentation 的错误处理代码 我正在使用以下 JsonSerializerSettings errors = new JsonErrors(); j
我正在为我的类属性的驼峰式外壳使用以下设置。 JsonSerializerSettings settings = new JsonSerializerSettings() {
如果我在我的项目中使用相同的设置,我可以实例化我的 JsonSerializerSettings 的单个静态副本并在整个过程中使用它吗? 例如: private static readonly Jso
在使用 json.net 时,我需要调整(反)序列化器设置,因此我创建一个 JsonSerializerSettings 实例并按如下方式使用它: JsonConvert.DeserializeObj
在使用 json.net 时,我需要调整(反)序列化器设置,因此我创建一个 JsonSerializerSettings 实例并按如下方式使用它: JsonConvert.DeserializeObj
我已经为 JSON.NET 设置了全局转换器默认值,如下所示: var jsonSerializerSettings = new JsonSerializerSettings
我在我的 asp.net mvc 项目中使用 azure 缓存作为缓存提供程序与 c#我使用此方法通过 JsonSerializerSettings 序列化我的数据 public static Jso
尝试设置 JsonOutputFormatter 选项: var jsonFormatter = (JsonOutputFormatter) options.OutputFormatters.Firs
给定一个 JsonSerializerSettings 对象、一个类型和一个 System.Reflection.PropertyInfo 对象,我如何确定: 1) 当使用给定设置使用 JSON.Ne
有什么方法可以从 JsonSerializer 类中取出设置并在新的 JsonSerializer 中重新实现它们? 似乎没有任何方法可以做那样的事情。我发现最好的是通过反射调用的私有(private
我有一个带有 CosmosDB 输出绑定(bind)的 Azure 函数,如下所示: public static class ComponentDesignHttpTrigger { [Fun
有时我需要通过 Json.NET 抑制 "$type" 属性的输出,即使由 JsonPropertyAttribute.ItemTypeNameHandling 指定也是如此.如何做到这一点? 我的根
我想使用自定义 JsonSerializerSettings 使用 DocumentDb API 创建文档。谁能告诉我如何做到这一点? 我尝试过设置 JsonConvert.DefaultSettin
我在使用 向服务器发送消息时收到以下错误SignalR 2.0.0 : SignalR: The reader's MaxDepth of 20 has been exceeded. 我使用 Unit
使用 Newton.Json 进行 Json 序列化。当我必须使用 Json 序列化一个具有字节数组属性的对象,然后以十六进制格式显示字节数组时,应用什么 JsonSerializerSettings
在我正在做的 C# 应用程序中 var settings = new ConnectionSettings(node); settings.ModifyJsonSerializerSettings(n
我在 .net 中有一个代码将请求序列化为 json 格式......代码是这样的。 var ops = new Newtonsoft.Json.JsonSerializerSettings();
我知道 ASP.NET Web API native 使用 Json.NET 来(反)序列化对象,但是有没有办法指定您希望它使用的 JsonSerializerSettings 对象? 例如,如果我想
我是一名优秀的程序员,十分优秀!