I have a Json string from Visistat.com's API that I am trying to parse in C# with Json.Net. The Json string looks like:
[
["date", "uniques"],
["2014-04-15", "613"],
["2014-04-16", "631"],
["2014-04-17", "593"],
["2014-04-18", "466"],
["2014-04-19", "305"],
["2014-04-20", "294"],
["2014-04-21", "795"],
["2014-04-22", "666"],
["2014-04-23", "625"],
["2014-04-24", "571"],
["2014-04-25", "506"],
["2014-04-26", "342"],
["2014-04-27", "351"],
["2014-04-28", "720"],
["2014-04-29", "606"],
["2014-04-30", "588"],
["2014-05-01", "508"],
["2014-05-02", "545"],
["2014-05-03", "345"],
["2014-05-04", "379"],
["2014-05-05", "833"],
["2014-05-06", "635"],
["2014-05-07", "596"],
["2014-05-08", "530"],
["2014-05-09", "539"],
["2014-05-10", "322"],
["2014-05-11", "290"],
["2014-05-12", "734"],
["2014-05-13", "684"],
["2014-05-14", "555"],
["2014-05-15", "511"]
]
I've created an object to deserialize this into:
public class DateUnique
{
public DateTime date { get; set; }
public int uniques { get; set; }
}
I'm then trying to parse the Json string with:
List<DateUnique> dateuniques = JsonConvert.DeserializeObject<List<DateUnique>>(json);
I then get this Exception:
Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'VisiStatSystem.DateUnique' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly. To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array. Path '[0]', line 1, position 2.
I don't see any samples in the Json.net documentation that shows how to deserialize a Json string that looks like what is returned by the VisiStat Api. Any help appreciated!