I receive a JSON text from an API call, and one of the properties can have a string value that sometimes equals to false, this is where the problem begins. Since the value type must be ExternalDownload, when I get false value I need to make the ExternalDownload equals to null.
JSON example
http://coub.com/api/v2/coubs/20971754
Data model
public partial class ExternalDownload
{
[JsonProperty("type")]
public DownloadType Type { get; set; }
[JsonProperty("url")]
public Uri Url { get; set; }
}
Enum
public enum DownloadType
{
Youtube,
Vimeo,
Vk,
Instagram,
Vine,
Wimp,
Facebook,
Odnoklassniki,
Funnyordie,
Carambatv,
CollegeHumor,
LiveLeak,
Dailymotion,
TetTv
}
Exception
Newtonsoft.Json.JsonSerializationException: 'Error converting value False to type 'Coub.Net.Objects.ExternalDownload'. Path 'external_download', line 1, position 3093.'
ArgumentException: Could not cast or convert from System.Boolean to Coub.Net.Objects.ExternalDownload.
"False"orfalse(without quotes)? If it's a string thenEnumMembershould just work, but if it's a JSON Boolean primitive (see json.org for details on the difference) then you will need to do something manual.falseand not"false", now I understand the problem.enumhas thefalsevalue but theExternalDownload.