parsing an enumeration in JSON.net

前端 未结 1 586
日久生厌
日久生厌 2020-12-03 21:01

i\'m using JSON.net (maybe v3.5ish? it\'s from oct. 2010). and i\'m trying to deserialize some json into an enumeration:

geometryType: \"esriGeometryPolygon\"

<
相关标签:
1条回答
  • 2020-12-03 21:44

    According to JSON.NET documentation, default behavior is to use int value for Enums : http://james.newtonking.com/projects/json/help/SerializationGuide.html

    You can change that by adding a JsonConverter attribute with StringEnumConverter on your enum...

    /// <summary>
    /// The geometry type.
    /// </summary>
    [DataContract]
    [JsonConverter(typeof(StringEnumConverter))]
    public enum GeometryType
    

    Documentation: Serialize with JsonConverters

    0 讨论(0)
提交回复
热议问题