Deserialization with changing Property names

Jun 22, 2010 at 4:14 AM

Hi,

I've been having an issue trying to get the Twitter trends json feed to deserialize correctly, and was hoping that someone might be able to help.

An example of the feed is here:

{ "as_of" : 1277174777,
"trends" : { "2010-06-22 03:00:00" : [ { "name" : "CALA BOCA TADEU SCHMIDT",
"query" : "CALA BOCA TADEU SCHMIDT"
},
{ "name" : "Summer Solstice",
"query" : "Summer Solstice"
},
{ "name" : "Nelson Trad",
"query" : "Nelson Trad"
},
{ "name" : "Cristiano Ronaldo",
"query" : "Cristiano Ronaldo"
},
{ "name" : "#blackpeoplerules",
"query" : "#blackpeoplerules"
},
{ "name" : "Pretty Little Liars",
"query" : "Pretty Little Liars"
},
{ "name" : "iOS4",
"query" : "iOS4"
},
{ "name" : "Berger",
"query" : "Berger"
},
{ "name" : "iOS",
"query" : "iOS"
},
{ "name" : "#cnnhelpgulf",
"query" : "#cnnhelpgulf"
}
] }
}

The problem is, that the list of trends is named uniquely to change with the time, so that i can't set the [JsonProperty("xxx")] to a constant name. My classes for deserialization are here:

[JsonObject(MemberSerialization.OptIn)]
        public class Trends
        {
            [JsonProperty("as_of")]
            public string as_of { getset; }

            [JsonProperty("trends")]
            public TrendList trends { getset; }
        }

        [JsonObject(MemberSerialization.OptIn)]
        public class TrendList
        {
            [JsonProperty]
            public List<Trend> trendList{get;set;}

        }

        [JsonObject(MemberSerialization.OptIn)]
        public class Trend
        {
            [JsonProperty("name")]
            public string name { getset; }
            [JsonProperty("query")]
            public string query { getset; }
        }

 When I use a static json string and set the JsonProperty for trendList to "2010-06-22 03:00:00" for example, it does work. Is there another way that I should be deserializing this? Thanks very much for any help!

Tommy