Json.NET - How to serialize a class using custom resolver

Posted by Mendy on Stack Overflow See other posts from Stack Overflow or by Mendy
Published on 2010-02-23T01:33:10Z Indexed on 2010/03/15 10:49 UTC
Read the original article Hit count: 549

Filed under:
|
|

I want to serialize this class:

public class CarDisplay
{
    public string Name { get; set; }
    public string Brand { get; set; }
    public string Year { get; set; }

    public PictureDisplay[] Pictures { get; set; }
} 

public class PictureDisplay
{
    public int Id { get; set; }
    public string SecretKey { get; set; }
    public string AltText { get; set; }
}

To this Json test:

{ Name: "Name value", Brand: "Brand value", Year: "Year value", Pictures: ["url1", "url2", "url3"] }

Note that each Car have an pictures array with only url string, instead of all the properties that Picture class have.

I know that Json.NET have the notion of Custom Resolver, but I don't sure exactly how to use it.

© Stack Overflow or respective owner

Related posts about json.net

Related posts about JSON