Put it simply, I am trying this DeserializeObject
method:
var page = JsonConvert.DeserializeObject<OneColumnPage>(response.Content);
This is currently not working.
Let's say I have this interface:
public interface IPageType
{
[JsonProperty("@type")]
string Type { get; set; }
[JsonProperty("name")]
string Name { get; set; }
[JsonProperty("title")]
string Title { get; set; }
[JsonProperty("metaKeywords")]
string MetaKeywords { get; set; }
[JsonProperty("metaDescription")]
string MetaDescription { get; set; }
[JsonProperty("headerContent")]
IList<IContentType> HeaderContent { get; set; }
[JsonProperty("mainContent")]
IList<IContentType> MainContent { get; set; }
}
I have an implementing class which is defined as:
public class OneColumnPage : IPageType
{
public string Type { get; set; }
public string Name { get; set; }
public string Title { get; set; }
public string MetaKeywords { get; set; }
public string MetaDescription { get; set; }
public IList<IContentType> HeaderContent { get; set; }
public IList<IContentType> MainContent { get; set; }
}
Currently, I am having difficulties deserializing the MainContent
. How can I generate the MainContent
dynamically? I have several implementations of IContentType
.
I have 2 examples of classes implementing the IContentType
:
public class RichTextMain : IContentType
{
public string Type { get; set; }
public string Name { get; set; }
[JsonProperty("content")]
public string Content { get; set; }
}
public class HorizontalRecordSpotlight : IContentType
{
public string Type { get; set; }
public string Name { get; set; }
[JsonProperty("title")]
public string Title { get; set; }
[JsonProperty("records")]
public List<Record> Records { get; set; }
}