草庐IT

newtonsoft

全部标签

c# - Newtonsoft JSON 动态属性名称

有没有办法在序列化期间更改数据属性的名称,以便我可以在我的WEBApi中重用此类。例如,如果我要返回用户的分页列表,则数据属性应序列化为“用户”,如果我要返回项目列表,则应称为“项目”等。这样的事情是否可能:publicclassPagedData{[JsonProperty(PropertyName="Setfromconstructor")]??publicIEnumerableData{get;privateset;}publicintCount{get;privateset;}publicintCurrentPage{get;privateset;}publicintOffse

c# - Newtonsoft Json 中的 TypeName 处理注意事项

关于this链接,在备注部分提到:TypeNameHandlingshouldbeusedwithcautionwhenyourapplicationdeserializesJSONfromanexternalsource.IncomingtypesshouldbevalidatedwithacustomSerializationBinderwhendeserializingwithavalueotherthanTypeNameHandling.None.在什么情况下,如果使用TypeNameHandling.All序列化/反序列化来自外部源的JSON会有害?一个工作示例将不胜感激。

c# - 使用 Newtonsoft JSON 的 ObjectCreationHandling 的说明?

我正在追踪一个错误,我注意到NewtonsoftJSON会将项目附加到List已在默认构造函数中初始化。我在C#聊天中做了更多挖掘并与一些人讨论,我们注意到此行为并不适用于所有其他集合类型。https://dotnetfiddle.net/ikNyiTusingSystem;usingNewtonsoft.Json;usingSystem.Collections.Generic;usingSystem.Collections.ObjectModel;publicclassTestClass{publicCollectionCollection=newCollection(new[]{"

c# - 使用 Newtonsoft Json.Net 反序列化为 IEnumerable 类

我有一个项目目前正在使用Json.Net来处理像这样的Json反序列化类:publicclassFoo{publicGuidFooGuid{get;set;}publicstringName{get;set;}publicListBars{get;set;}}publicclassBar{publicGuidBarGuid{get;set;}publicstringDescription{get;set;}}到目前为止一切正常。为了让迭代更简单,我做了Foo类(class)工具IEnumerable像这样:publicclassFoo:IEnumerable{publicGuidFoo

c# - 使用 newtonsoft 从 Json 字符串中删除属性

我有以下JSON字符串:{"results":[{"id":11,"name":"EmployeeA","isEmployee":true},{"id":12,"name":"EmployeeB","isEmployee":true},{"id":13,"name":"EmployeeC","isEmployee":true},{"id":14,"name":"ContractorA","isEmployee":false},{"id":15,"name":"ContractorB","isEmployee":false}],"totalItems":5}我需要从中删除id和isEmp

c# - 如何使用 Newtonsoft.Json 反序列化 JSON 数组

[{"receiver_tax_id":"1002","total":"6949,15","receiver_company_name":"DasCompany","receiver_email":"info@another.com","status":0},{"receiver_tax_id":"1001","total":"39222,49","receiver_company_name":"SADcompany","receiver_email":"info@mail.com","status":1}]嗨,这是我的Json数据,但我无法反序列化它。我只想检查“状态”值。(第一个对

c# - Newtonsoft.json 程序集包版本不匹配

我正在尝试使用SocketIO4Net在.net中创建socket.io客户端。似乎SocketIO4Net依赖于Newtonsoft.Json>=4.0.8。我也在用PushSharp具有>=4.5.10的Newtonsoft.Json依赖项的库。当我第一次安装PushSharp时,我得到了NewtonSoft.Json4.5.11,我认为这个版本也应该支持SocketIO4Net,因为它是一个更高的版本,但是每当我尝试连接到socket.io服务器时,我都会收到这个错误。Couldnotloadfileorassembly'Newtonsoft.Json,Version=4.0.8

c# - 无法加载文件或程序集 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' 或其依赖项之一

我有一个以前使用VS2013在Windows8.1上构建的WinJS项目。最近,我通过创建一个空白的Javascript通用Windows10项目,然后添加了旧项目中的所有文件,将此项目升级到通用Windows10。我有Windows运行时组件和SQLite类库。我添加了通用Windows运行时组件和通用类库,并将我的所有文件从旧项目复制到相应位置。我以某种方式设法消除了所有构建错误。我安装了所有必需的SQLite-net、适用于通用Windows平台的SQLite、Newtonsoft等。但是当我运行应用程序并在Windows运行时组件中调用native方法时,它会出现一些奇怪的错误

c# - 如何使用 Newtonsoft.Json 将对象序列化为带有类型信息的 json?

当我序列化某些类型的对象时,我想在JSON中拥有一个类型名称的属性。我写了一个转换器:publicclassTypeInfoConverter:JsonConverter{privatereadonlyIEnumerable_types;publicTypeInfoConverter(IEnumerabletypes){Contract.Requires(types!=null);_types=types;}publicoverridevoidWriteJson(JsonWriterwriter,objectvalue,JsonSerializerserializer){varjObj

c# - NewtonSoft 在运行时添加 JSONIGNORE

我想使用NewtonSoftJSON序列化一个列表,我需要在序列化时忽略其中一个属性,我得到了以下代码publicclassCar{//includedinJSONpublicstringModel{get;set;}//ignored[JsonIgnore]publicDateTimeLastModified{get;set;}}但是我在我的应用程序中的许多地方都使用了这个特定类Car,我只想在一个地方排除该选项。我可以在我需要的特定位置动态添加[JsonIgnore]吗?我该怎么做? 最佳答案 无需执行其他答案中解释的复杂内容。