I have a situation where I need to parse JSON that is sometimes an array and other times a single variable. So I'm unsure how to create my C# classes.
There is a single screen item, but question and answer are sometimes an array.
I'm using Newtonsoft.Json
JSON EXAMPLE 1:
{
"screen": {
"id": "39968400",
"name": "Role Requirements for Job 39967376",
"successful": "True",
"question": {
"id": "1",
"type": "Text",
"text": "What is your residential city and postcode?",
"answer": {
"id": "1",
"selected": "True",
"text": "Brisbane, 3000"
}
}
}
}
JSON EXAMPLE 2:
{
"screen": {
"id": "98726",
"name": "Copy of Simple Screening Standard Form 6900",
"successful": "True",
"question": [
{
"id": "440562",
"type": "MultipleChoiceOneAnswer",
"text": "What is your current work status?",
"answer": [
{
"id": "1",
"selected": "True",
"text": "Looking"
},
{
"id": "2",
"text": "Not Looking"
}
]
},
{
"id": "440563",
"type": "MultipleChoiceOneAnswer",
"text": "When are you available to begin employment?",
"answer": [
{
"id": "1",
"selected": "True",
"text": "Now"
},
{
"id": "2",
"text": "2 weeks"
}
]
}
]
}
}