I have a response coming from a 3rd party service in Json format. The fields are almost the same except if a validation fails it crashes the program. The Json returned is
{
"response": 0,
"sites": {
"site": {
"customer": [{
"validation": {
"customer.dob": "dob required",
"customer.surname": "surname required"
}
}]
}
},
"records": {
"insertcount": 0,
"deletecount": 0
},
"referrals": []
}
And
{
"sucession": 0,
"sites": {
"site": "please try later."
},
"records": {
"insertcount": 0,
"deletecount": 0
},
"referrals": []
}
To read the Json i create a class for the above Json using an online tool and then i deserilize it
RootObject ro = JsonConvert.DeserializeObject<RootObject>(JsonInStringFormat);
How could i build this so that one class can handle the Json accordingly? OR is there another way to do the same? The Json returned is held in a string variable (note the JsonInStringFormat
)
Edit - RootObject
public class RootObject
{
public int response { get; set; }
public Sites sites { get; set; }
public Records records { get; set; }
public List<object> referrals { get; set; }
}