Newtonsoft.Json中的ArgumentNullException-CreateObjectUsingCreatorWithParameters

我正在尝试从JSON反序列化联系人的复杂对象,但是我收到了ArgumentNullException

错误堆栈跟踪为:

[ArgumentNullException: Value cannot be null.
Parameter name: method]
   System.Delegate.DelegateConstruct(Object target,IntPtr slot) +0
   Void .ctor(System.Object,IntPtr)(Object[] ) +132
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObjectUsingCreatorWithParameters(JsonReader reader,JsonObjectContract contract,JsonProperty containerProperty,ObjectConstructor`1 creator,String id) +1917
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader,Type objectType,JsonContract contract,JsonProperty member,JsonContainerContract containerContract,JsonProperty containerMember,Object existingValue) +787
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader,Object existingValue) +188
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list,JsonReader reader,JsonArrayContract contract,String id) +1522
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader,Object existingValue,String id) +434
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader,Object existingValue) +245
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property,JsonConverter propertyConverter,Object target) +404
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject,String id) +2540
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader,Object existingValue) +839
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader,Object existingValue) +188
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader,Boolean checkAdditionalContent) +780
   Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader,Type objectType) +341
   Newtonsoft.Json.JsonConvert.DeserializeObject(String value,Type type,JsonSerializerSettings settings) +263
   Newtonsoft.Json.JsonConvert.DeserializeObject(String value,JsonSerializerSettings settings) +57
   activeCampaign.Net.Services.ContactService.getcontact(Int32 id) +139
   ArtsHub.active_campaign.btngetcontact_Click(Object sender,EventArgs e) +167
   system.web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +155
   system.web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint) +3804

我确实尝试过更改DateTime的某些属性吗?字符串或对象,但无济于事。

该错误在Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObjectUsingCreatorWithParameters中很深,似乎是我所不知道的。

解决方案的链接为https://dotnetfiddle.net/uIgRXS

希望在此问题上能有所帮助。

ft983110 回答:Newtonsoft.Json中的ArgumentNullException-CreateObjectUsingCreatorWithParameters

Functor类中,您具有属性swap,但是代码中没有匹配的类-这意味着编译器正在使用类Contact类,并且无法反序列化JSON插入该类。

解决方案:

将Action类添加到文件中

List<Action> Actions

注意:

我如何找到答案?我删除了JSON的不同部分并运行了代码,直到发现错误为止。当我发现JSON的哪个部分导致了问题时,我检查了定义该对象的对象并寻找匹配的类。当我在代码中找不到为该对象定义的类时,就添加了它。

您应该尝试将问题最小化到尽可能小的代码,即删除JSON部分。这将删除起作用的部分,并隔离出失败的确切代码/ JSON。

希望有帮助:-)

本文链接:https://www.f2er.com/3097912.html

大家都在问