我无法理解我在Mac上使用Json.Net时遇到的问题。 我想序列化/反序列化下面的对象。Json.Net(8.0)在Mono 4.5 Mac上创建StringEnumConverter时出错
该代码在Windows上运行时没有问题,但在Mac上生成Newtonsoft.Json.JsonException“Error creating StringEnumConverter”(也在图中显示)。我希望有人在代码或错误消息中看到某些东西,这可能会指向正确的方向。 该对象包含更多的字段,但错误听起来像它与枚举有关。我在Xamarin 6/Mono .Net 4.5中构建,我正在使用Json.Net 8.0.3进行.Net 4.5。任何帮助不胜感激。
编辑1: 卸下JsonConverter(typeof运算(StringEnumConverter))装修避免了异常 - 但是,枚举序列化为整数一次。
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace Lib
{
[DataContract(IsReference = true)]
public class Construction : LibraryComponent
{
public Construction() { }
public override string ToString() { return Serialization.Serialize(this); }
[DataMember]
public string Construction { get; set; } = "defaultConstruction";
...
[DataMember, JsonConverter(typeof(StringEnumConverter)), DefaultValue(InConvAlgo.TARP)]
public InConvAlgo SurfaceConvectionModelInside { get; set; } = InConvAlgo.TARP;
[DataMember, JsonConverter(typeof(StringEnumConverter)), DefaultValue(OutConvAlgo.DOE2)]
public OutConvAlgo SurfaceConvectionModelOutside { get; set; } = OutConvAlgo.DOE2;
...
[DataMember, DefaultValue(1)]
public int Priority { get; set; } = 1;
}
public enum InConvAlgo { Simple, TARP, TrombeWall, AdaptiveConvectionAlgorithm };
public enum OutConvAlgo { DOE2, TARP, MoWiTT, SimpleCombined, AdaptiveConvectionAlgorithm }; // DOE-2,
}