Ejemplo n.º 1
0
    private static void ParseAndDump(string json)
    {
        DateAndCount dac = JsonConvert.DeserializeObject <DateAndCount>(json);

        Console.WriteLine("Date: " + dac.Date);
        Console.WriteLine("Count: " + dac.Count);
        Console.WriteLine();
    }
Ejemplo n.º 2
0
    public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
    {
        JObject      jo  = JObject.Load(reader);
        DateAndCount dac = new DateAndCount();

        dac.Date = (DateTime?)jo["Date"];
        // put the value of the first integer property from the JSON into Count
        dac.Count = (int)jo.Properties().First(p => p.Value.Type == JTokenType.Integer).Value;
        return(dac);
    }