The error I am getting is as follows:
the current JSON array (e.g. [1,2,3]) into type 'Dorman.SpecialOrderSKU.Models.Questions' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
What I have tried:
JSON:
{
"PartNumber": "123-456",
"NumberOfQuestions": 5,
"dateLastModified": "",
"status": "active",
"type": "question",
"Questions": [
{
"validationID": 1,
"QuestionID": 1,
"Question": "some question text",
"ResponseType": "Single_Select",
"Option_List": {
"1": "option 1 text",
"2": "option 2 text",
"3": "option 3 text"
}
},
{
"validationID": 1,
"QuestionID": 2,
"Question": "some question text",
"ResponseType": "Multi_Select",
"Option_List": [
"option 4 text",
"option 5 text",
"option 6 text"
]
},
{
"validationID": 6,
"QuestionID": 3,
"Question": "some question text",
"ResponseType": "Number"
},
{
"validationID": 2,
"QuestionID": 4,
"Question": "some question text",
"ResponseType": "String"
},
{
"validationID": 3,
"QuestionID": 5,
"Question": "some question text",
"ResponseType": "Boolean"
}
],
"id": "ab3fcc42-9d5a-48d4-96ea-388c5edd886f",
"_rid": "HopBAKbRQQ0BAAAAAAAAAA==",
"_self": "dbs/HopBAA==/colls/HopBAKbRQQ0=/docs/HopBAKbRQQ0BAAAAAAAAAA==/",
"_etag": "\"2e00b41c-0000-0200-0000-5ed857d40000\"",
"_attachments": "attachments/",
"_ts": 1591236564
}
I have used the below class for deserializing
public class QuestionsAnswers
{
[JsonProperty("PartNumber")]
public string PartNumber { get; set; }
[JsonProperty("NumberOfQuestions")]
public int NumberOfQuestions { get; set; }
[JsonProperty("dateLastModified")]
public string DateLastModified { get; set; }
[JsonProperty("status")]
public string Status { get; set; }
[JsonProperty("type")]
public string Type { get; set; }
public QuestionList Questions { get; set; }
[JsonProperty("id")]
public string ID { get; set; }
[JsonProperty("_rid")]
public string Rid { get; set; }
[JsonProperty("_self")]
public string Self { get; set; }
[JsonProperty("_etag")]
public string Etag { get; set; }
[JsonProperty("_attachments")]
public string Attachments { get; set; }
[JsonProperty("_ts")]
public int Ts { get; set; }
}
public class QuestionList : ICollection<Questions>
{
public List<Questions> questionList { get; set; }
public int Count
{
get { return questionList.Count; }
}
public bool IsReadOnly
{
get
{
return false;
}
}
public void Add(Questions item)
{
questionList.Add(item);
}
public void Clear()
{
questionList.Clear();
}
public bool Contains(Questions item)
{
return questionList.Contains(item);
}
public void CopyTo(Questions[] array, int arrayIndex)
{
questionList.CopyTo(array, arrayIndex);
}
public IEnumerator<Questions> GetEnumerator()
{
return questionList.GetEnumerator();
}
public bool Remove(Questions item)
{
return questionList.Remove(item);
}
IEnumerator<Questions> IEnumerable<Questions>.GetEnumerator()
{
foreach (Questions ApptReason in questionList)
{
yield return ApptReason;
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
}
public class Questions
{
public int ValidationID { get; set; }
public int QuestionID { get; set; }
public string Question { get; set; }
public string ResponseType { get; set; }
}
Can some one help me on this