Partially deserialize with JSON.NET, keeping some fields raw

流过昼夜 提交于 2019-12-10 14:34:03

问题


I have a document like this

{
    "Field1": 1,
    "Field2": 2,
    "Field3": {
        Type: "TheMotherLoad"
    }
}

Which i want to convert into this class, but keeping field 3 "raw/as-is".

public class Fields {
    public int Field1 { get; set; }
    public int Field2 { get; set; }
    public string Field3 { get; set; }
}

The result should be

Field1 = 1, 
Field2 = 2, 
Field3 = "{ Type: "TheMotherLoad" }"

Possible with Json.NET?


回答1:


Field3 could be a JObject. When you need JSON just call Field3.ToString()



来源:https://stackoverflow.com/questions/15828230/partially-deserialize-with-json-net-keeping-some-fields-raw

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!