I have an inconsistent JSON file, that was likely generated by hand. Here's a truncated example:
[
{
"Generic Name": "Lurasidone",
"Brand Name": ["Latuda"]
}
{
"Generic Name": "Lisdexamfetamine",
"Brand Name": "Vyvanse"
}
]
Since "Brand Name" is [] for one, and just a regular string for another, how do I take care of this in .NET?
public class Drug
{
[JsonProperty("Generic Name")]
public string GenericName {get; set;}
[JsonProperty("Brand Name")]
public string[] BrandName {get; set;}
}
List<Drug> a = JsonConvert.DeserializeObject<List<Drug>>(
File.ReadAllText("d.json"));
Results in the error:
Error converting value "Vyvanse" to type 'System.String[]'. Path '[1].Brand Name', line 20, position 26.