JSON.Net Ignore Property during deserialization

前端 未结 6 647
别跟我提以往
别跟我提以往 2020-12-29 19:55

I have a class set up as follows:

public class Foo
{
    public string string1 { get; set; }
    public string string2 { get; set; }
    public string string3         


        
6条回答
  •  孤独总比滥情好
    2020-12-29 20:38

    This is a lame workaround but you could make a method to manually load the json. If it's too much data to load without an automatic deserializer just remove the nodes that you don't want. This is a lot slower though.

    public static List FromJson(string input) {
        var json = JToken.Parse(input);
        json["key"].Remove();
        var foo = JsonConvert.DeserializeObject>(json.ToString());
    
    }
    

    This is an interesting problem I wonder if anyone has a better solution for it.

提交回复
热议问题