I have a sample JSON that when i deserialize i get "object reference not set to instance of an object" because i found out some that sometimes the field is missing then it will reappear again.
the json is similar to this
{
"title": "Example",
"type": "object",
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"age": {
"description": "Age in years",
"type": "integer",
"minimum": 0
}
}
}
if i deserialize this and map it to the corresponding fields the result is OK
but if for example the "Age" is missing
{
"title": "Example",
"type": "object",
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
},
"required": ["firstName", "lastName"]
}
it will throw an error "object reference not set to instance of an object" how do i ignore the age if it's missing in JSON?
if(MyObject.Properties.Age==null) { MyObject.Properties.Age = new Age();}then deserialize it.