I'm having a hard time deserializing a JSON to a concrete type, because I think the JSON i'm working with has been serialized incorrectly.
The JSON looks like this:
{
"D16":"{\r\n \"OptionsList\": [\r\n {\r\n \"Id\": 0,\r\n \"Value\": \"Yes\",\r\n \"IsHighlighted\": false,\r\n \"Color\": \"\",\r\n \"FieldsToProcess\": []\r\n },\r\n {\r\n \"Id\": 1,\r\n \"Value\": \"No\",\r\n \"IsHighlighted\": false,\r\n \"Color\": \"\",\r\n \"FieldsToProcess\": []\r\n }\r\n ],\r\n \"SingleSelectedOption\": null,\r\n \"SelectedOptions\": [\r\n {\r\n \"Id\": 0,\r\n \"Value\": \"Yes\",\r\n \"IsHighlighted\": false,\r\n \"Color\": \"\",\r\n \"FieldsToProcess\": []\r\n },\r\n {\r\n \"Id\": 1,\r\n \"Value\": \"No\",\r\n \"IsHighlighted\": false,\r\n \"Color\": \"\",\r\n \"FieldsToProcess\": []\r\n }\r\n ]\r\n}",
"D5":"{\r\n \"OptionsList\": [\r\n {\r\n \"Id\": 0,\r\n \"Value\": \"Male\",\r\n \"IsHighlighted\": false,\r\n \"Color\": \"\",\r\n \"FieldsToProcess\": []\r\n },\r\n {\r\n \"Id\": 1,\r\n \"Value\": \"Female\",\r\n \"IsHighlighted\": false,\r\n \"Color\": \"\",\r\n \"FieldsToProcess\": []\r\n }\r\n ],\r\n \"SingleSelectedOption\": {\r\n \"Id\": 0,\r\n \"Value\": \"Male\",\r\n \"IsHighlighted\": false,\r\n \"Color\": \"\",\r\n \"FieldsToProcess\": []\r\n },\r\n \"SelectedOptions\": []\r\n}",
"D15":"3213131",
"D14":"321321",
"D13":"213213",
"D12":"213213",
"D4":"Kerkata",
"D3":"Kero",
"D11":"1323",
"D10":"1321",
"D9":"321",
"D8":"31321",
"D7":"kero@gmail.com",
"D1":"Kerim",
"D2":"Emurla"
}
As you can see my problem is that the D16 object starts with quotes, which means I can't deserialize it to a concrete type.
I need to convert D16(I can have N number of those object) to a normal object in order to use JsonConvert.DeserializeObject<T>
to convert it to the type I want.
Edit: This is what my class i'm trying to deserialize to looks like:
public class FormDescriptionDTO
{
[JsonProperty(FormDescriptionsConstansts.FirstName)]
public string FirstName { get; set; }
[JsonProperty(FormDescriptionsConstansts.LastName)]
public string LastName { get; set; }
[JsonProperty(FormDescriptionsConstansts.MiddleName)]
public string MiddleName { get; set; }
[JsonProperty(FormDescriptionsConstansts.Preferred)]
public string Preferred { get; set; }
[JsonProperty(FormDescriptionsConstansts.Gender)]
public OptionsDTO Gender { get; set; }
[JsonProperty(FormDescriptionsConstansts.Email)]
public string Email { get; set; }
[JsonProperty(FormDescriptionsConstansts.SSN)]
public string SSN { get; set; }
[JsonProperty(FormDescriptionsConstansts.WorkPhone)]
public string WorkPhone { get; set; }
[JsonProperty(FormDescriptionsConstansts.CellPhone)]
public string CellPhone { get; set; }
[JsonProperty(FormDescriptionsConstansts.HomePhone)]
public string HomePhone { get; set; }
}
In this case the D16 should map to the Gender
property.