junkone junkone - 27 days ago 20
C# Question

How can i declare list in a Json object?

I have a json object declaration in which i want to use a list of DateTime. How can i declare it? I get a error in the current definition.

public class TurtleTrade
{
[JsonProperty("Powerbars")]
public int Powerbars { get; set; }
[JsonProperty("PowerbarsTime")]
public List<DateTime>() PowerbarsTime { get; set; } // Error here
}

Answer

As you stated the issues/Error is not because of the [JsonProperty("PowerbarsTime")] You can define List under it. The real issues is the declaration syntax of List<T>. List<DateTime>() is not a valid declaration of a List of DateTime it must be List<DateTime> So public List<DateTime>() PowerbarsTime { get; set; } should be like this :

public List<DateTime> PowerbarsTime { get; set; }