我有以下对象,我正在尝试使用 Json.NET 将其序列化为 Json
[Serializable]
public class FlightSelection : IEquatable<FlightSelection>
{
public static readonly DateTime InitialDate;
public FlightSelection();
public FlightWeekSelectionType FlightWeekSelectionType { get; set; }
public bool IsValidProposalLineWeeksExists { get; }
public int Play { get; set; }
public List<ProposalLineWeek> ProposalLineWeeks { get; set; }
public int SelectedCount { get; }
public int Skip { get; set; }
public void ApplyPattern();
public bool Equals(FlightSelection other);
public override bool Equals(object obj);
public bool[] ToBoolArray();
public override string ToString();
}
我尝试使用以下代码对其进行序列化:
var jsSettings = new JsonSerializerSettings();
var fs = new FlightSelection();
string json = JsonConvert.SerializeObject(fs, Formatting.None, jsSettings);
我收到以下错误:The 'obj' argument is not a FlightSelection object.
我真的不明白为什么。我在对象中看到“obj”的唯一位置是 Equals 方法。为什么序列化器关心一个方法。
我错过了一些简单的东西吗?
编辑:按照评论中的要求进行堆栈跟踪:
在 CC.Fusion.Business.Model.FlightSelection.Equals(Object obj) 在 System.Collections.Generic.ObjectEqualityComparer
1.IndexOf(T[] array, T value, Int32 startIndex, Int32 count) at System.Array.IndexOf[T](T[] array, T value, Int32 startIndex, Int32 count) at System.Collections.Generic.List
1.Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CheckForCircularReference(JsonWriter writer, Object value, JsonProperty property, JsonContract contract, JsonContainerContract containerContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues(JsonWriter writer,对象值、JsonContainerContract 合同、JsonProperty 成员、JsonProperty 属性、JsonContract& memberContract、Object& memberValue) 在 Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty) 在 Newtonsoft。 Json.Serialization.JsonSerializerInternalWriter。SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member , JsonContainerContract 集合合约,JsonProperty containerProperty) 在 Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty) 在 Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty) (JsonWriter jsonWriter, 对象值,类型 objectType) 在 Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType) 在 Newtonsoft.Json.JsonSerializer.Serialize(JsonWriter jsonWriter, Object value, Type objectType) 在 Newtonsoft.Json.JsonConvert.SerializeObject(Object value , Type type, Formatting formatting, JsonSerializerSettings settings) at Newtonsoft.Json.JsonConvert.SerializeObject(Object value, Formatting formatting, JsonSerializerSettings settings) at APProxyServer.APProxy.GetProposal(Int32 proposalID) in c:\Code.Net\ClearChannel\Sandbox\ APProxyServer\APProxy\APProxy.svc.cs: SyncInvokeGetProposal(Object , Object[] , Object[] ) 处的第 194 行,位于 System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] 输入, Object[]& 输出)在 System.ServiceModel.Dispatcher。DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)