I am trying to read below JSON string in C#
{
"ModelState": {
"obj.SystematicDate": {
"_errors": [
{
"<Exception>k__BackingField": null,
"<ErrorMessage>k__BackingField": "A value is required."
}
],
"<Value>k__BackingField": null
},
"obj.CustomerId": {
"_errors": [
{
"<Exception>k__BackingField": null,
"<ErrorMessage>k__BackingField": "A value is required."
}
],
"<Value>k__BackingField": null
},
"obj.userId": {
"_errors": [
{
"<Exception>k__BackingField": null,
"<ErrorMessage>k__BackingField": "User Id is mandatory"
}
],
"<Value>k__BackingField": null
}
}
}
The above mentioned JSON string is response from an api call and it is dynamic. It can contain n number of 'obj.' properties.
I need to read that values and show error message as SystematicDate: A value is required , userId: User Id is mandatory and so on.
I tried below solutions but did not get the desired output.
var jsonStrin = "{'ModelState':{'obj.SystematicDate':{'_errors':[{' < Exception > k__BackingField':null,' < ErrorMessage > k__BackingField':'A value is required.'}],' < Value > k__BackingField':null},'obj.CustomerId':{'_errors':[{' < Exception > k__BackingField':null,' < ErrorMessage > k__BackingField':'A value is required.'}],' < Value > k__BackingField':null},'obj.userId':{'_errors':[{' < Exception > k__BackingField':null,' < ErrorMessage > k__BackingField':'User Id is mandatory'}],' < Value > k__BackingField':null}}}";
//var stuff=JsonConvert.DeserializeObject(jsonStrin);
//JObject o = JObject.Parse(jsonStrin);
var example1Model = new JavaScriptSerializer().Deserialize<ModelState>(jsonStrin);
public class ModelState {
public List<SystematicDateError> SystematicDate { get; set; }
public List<CustomerIdError> CustomerId { get; set; }
}
public class SystematicDateError
{
public List<string> _errors { get; set; }
}
public class CustomerIdError
{
public List<string> _errors { get; set; }
}
Please help me with this. Thanks in advance.