Here's what I've done so far
public enum TCountryNames
{
[Display(Name="America")]
cnUSA = 1,
[Display(Name="England")]
cnUK,
[Display(Name="CHINA")]
cnCHN
}
public class MyClass
{
public static List<KeyValuePair<string, int>> GetEnumList()
{
var list = new List<KeyValuePair<string, int>>();
foreach (var e in Enum.GetValues(typeof(TCountryNames)))
{
list.Add(new KeyValuePair<string, int>(e.ToString(), (int)e));
}
return list;
}
}
Result: [cnUSA,1] with total count 3 and without header
The result i want is [{"Id":1,"Name":"America"},{"Id":2,"Name":"England"}]
I've tried [JsonConverter(typeof(StringEnumConverter))] public TCountryNames Names{ get; set; }
I've also tried converting enum to array list var names = Enum.GetValues(typeof(TCountryNames)); ArrayList arrLst = new ArrayList() { names }; but both of them doesn't seems to be working.
*Any help will be appreciated. Thank You in Advance. *