bry*_*ich 20 c# json.net xamarin.ios
我正在使用JSON.net(也许v3.5ish?它来自2010年10月).我试图将一些json反序列化为枚举:
geometryType:"esriGeometryPolygon"
我有这个枚举:
/// <summary>
/// The geometry type.
/// </summary>
[DataContract]
public enum GeometryType
{
/// <summary>
/// Refers to geometry type Envelope
/// </summary>
[EnumMember(Value = "esriGeometryEnvelope")]
Envelope,
/// <summary>
/// Refers to geometry type MultiPoint
/// </summary>
[EnumMember(Value = "esriGeometryMultipoint")]
MultiPoint,
/// <summary>
/// Refers to geometry type MapPoint
/// </summary>
[EnumMember(Value = "esriGeometryPoint")]
Point,
/// <summary>
/// Refers to geometry type Polygon
/// </summary>
[EnumMember(Value = "esriGeometryPolygon")]
Polygon,
/// <summary>
/// Refers to geometry type Polyline
/// </summary>
[EnumMember(Value = "esriGeometryPolyline")]
Polyline
}
Run Code Online (Sandbox Code Playgroud)
但它抛出一个错误,说"错误转换值"esriGeometryPolygon"键入'... GeometryType'.
我在这里失踪了什么?
是因为它是旧版本(我正在使用monotouch端口:https://github.com/chrisntr/Newtonsoft.Json,一年内没有更新)?或者我的datacontract错了吗?
编辑:我将最新的JSON.NET移植到MT,我仍然得到完全相同的错误.
Rom*_*sse 39
根据JSON.NET文档,默认行为是对Enums使用int值:http://james.newtonking.com/projects/json/help/SerializationGuide.html
您可以通过在枚举上添加带有StringEnumConverter的JsonConverter属性来更改它...
/// <summary>
/// The geometry type.
/// </summary>
[DataContract]
[JsonConverter(typeof(StringEnumConverter))]
public enum GeometryType
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9496 次 |
| 最近记录: |