I am receiving a JSON structure that is somewhat unpredictable from a third party API. For example, I started with a class like this:
public Class UserTuple
{
public int uid {get; set;}
public String email {get; set;}
public Dictionary<string,int> stats {get; set;}
//Unknown structure here (Although I know its name)...
}
I can potentially make a class for this, but it will be quite nested...I do not care about the values in this part, so it seems like a waste. Is there a way to let JSON.NET know to ignore this unknown section?
PS: I am deserializing in this way:
JsonConvert.Deserialize<List<UserTuple>>(receivedJSON);
If you don't care about it, it seems like you just need to set JsonSerializerSettings.MissingMemberHandling
appropriately:
var settings = new JsonSerializerSettings
{
MissingMemberHandling = MissingMemberHandling.Ignore
};
var tuples = JsonConvert.DeserialiazeObject<List<UserTuple>>(json, settings);
See more on this question at Stackoverflow