I have been trying to mimic GoogleReader's Json output, particularly the subscription listing. I started out creating classes for deserialization but I don't have a full grasp of the concepts. It crashes when I really try to consume the Json file, but when I generate my own serialized file it looks just right. I don't know what's going wrong. Thus far this is the progress I made:
[DataContract(Name = "subscriptionsList")]
[Serializable]
public class Subscription
{
[DataMember(Name = "subscriptions")]
public List<SubscriptionItem> Subscriptions = new List<SubscriptionItem>();
public Subscription()
{
}
}
[DataContract(Name="subscriptionitem")]
[Serializable]
public class SubscriptionItem
{
[DataMember(Name = "id")]
internal string id;
public string Id
{
get
{
return id;
}
set
{
id = value;
}
}
[DataMember(Name="title")]
internal string title;
public string Title
{
get
{
return title;
}
set
{
title = value;
}
}
[DataMember(Name="sortid")]
internal string sortid;
public string SortId
{
get
{
return sortid;
}
set
{
sortid = value;
}
}
[DataMember(Name="firstitemmsec")]
internal string firstitemmsec;
public string LatestUpdate
{
get
{
return firstitemmsec;
}
set
{
firstitemmsec = value;
}
}
[DataMember(Name = "categories")]
internal Categories categories;
public Categories Categories
{
get
{
return categories;
}
set
{
categories = value;
}
}
}
[CollectionDataContract(Name = "categories")]
public class Categories : List<string>
{
public Categories()
: base()
{
}
public Categories(string[] items)
: base()
{
foreach (string item in items)
{
Add(item);
}
}
}
A comparison of the Json original format:
{"subscriptions":[{
"id":"feed/http://newsrss.bbc.co.uk/rss/sportonline_uk_edition/football/rss.xml",
"title":"BBC Sport | Football | UK Edition",
"categories":[],
"sortid":"C6CEC826",
"firstitemmsec":"1178119338469"
}]}
and the output of my DataContracts:
{"subscriptions":[{
"categories":[],
"firstitemmsec":null,
"id":"0",
"sortid":"0",
"title":"0th"
}]}