I am trying to convert the below JSON property into an object. The string array is kind of a mixed type: its elements may be strings or string arrays. (Although the string arrays only show up in the occasional record.)
I made the booster property a List<String>, which is fine, but the few rows that have the array at the end cause parsing to fail. Any ideas how I could handle this situation?
"booster": [
"land",
"marketing",
"common",
"common",
"common",
"common",
"common",
"common",
"common",
"common",
"common",
"common",
"uncommon",
"uncommon",
"uncommon",
[
"rare",
"mythic rare"
]
]
using(var db = new MTGFlexContext()){
JObject AllData = JsonConvert.DeserializeObject<JObject>(File.ReadAllText(path));
List<String> SetCodes = db.Sets.Select(x => x.Code).ToList();
foreach (var set in AllData)
{
try
{
Set convert = JsonConvert.DeserializeObject<Set>(set.Value.ToString()) as Set;
if (!SetCodes.Contains(set.Key))
{
convert.Name = set.Key;
foreach (var c in convert.Cards)
{
db.Cards.Add(c);
db.SaveChanges();
}
db.Sets.Add(convert);
db.SaveChanges();
}
}
}
}
The full json is 40mb http://mtgjson.com/