How to Read Countries, States, Cities data from Json file and Convert to List Objects in C#.

 Here I'm attaching the Json String of Countries List, States List, Cities List and also the scripts for all countries, states, cities.

You can just , use and convert the Json string to List Object and use them.

Models For Country, State, City:

public class CountryMaster
{
public int ID { get; set; }
public string CountryName { get; set; }
public string CountryCode { get; set; }
}
public class StateMaster
{
public int ID { get; set; }
public string StateName { get; set; }
public int CountryID { get; set; }
}
public class CityMaster
{
public int ID { get; set; }
public string CityName { get; set; }
public int StateID { get; set; }
}

Note: The above models are as per json 

 For Sample,

To get the country list you can use below code,

 var res = JsonConvert.DeserializeObject<List<CountryMaster>>("country json string"); 

Drive link:

drivelink    

Comments

Popular posts from this blog

Top MNC Interview Questions- Full Stack Developer

Interview Questions-2

How to get the user details, user current level, next level, Rank in sql server