Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Partially deserialize with JSON.NET, keeping some fields raw

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?

like image 915
Lars Stenberg Avatar asked Apr 05 '13 07:04

Lars Stenberg


1 Answers

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

like image 122
James Newton-King Avatar answered Oct 22 '22 16:10

James Newton-King