I have a json like this to read in c# but it showing null.
Provices.json contains this json
{
"Provinces": {
"States": [
{
"CountryId": 1,
"Name": "AA (Armed Forces Americas)",
"Abbreviation": null,
"Published": false,
"DisplayOrder": 0,
"Country": null,
"Id": 1
},
{
"CountryId": 1,
"Name": "AE (Armed Forces Europe)",
"Abbreviation": null,
"Published": false,
"DisplayOrder": 0,
"Country": null,
"Id": 54
}
]
}
}
start up file contains
services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));
services.Configure<Provinces>(Configuration.GetSection("Provinces"));
This is c# models
public class Provinces
{
public Provinces()
{
this.States = new List<State>();
}
public List<State> States { get; set; }
}
public class State
{
public int CountryId { get; set; }
public string Name { get; set; }
public string Abbreviation { get; set; }
public bool Published { get; set; }
public bool DisplayOrder { get; set; }
public string Country { get; set; }
public int Id { get; set; }
}
This is how I am reading this file which is giving me null values
public class UserService
{
public UserService(IOptions<AppSettings> appSettings,
IOptions<Provinces> states)
{
_appSettings = appSettings;
_states = states;
}
//Getting value from json
public List<State> GetStates()
{
var data = this._states.Value.States; // Zero count shows here
return new List<State>();
}
}
I am also reading AppSettings.json which is working fine but province.json is not working.Can You please tell what's wrong i did