C# コンソール アプリケーションでGoolge AJAX Feed APIを使用してリターン フィードを C# コレクションとして保存し、.net アプリケーションでこの .net コレクションを使用できるようにしたいと考えています。
Google が Java アクセス コード スニペットを提供していることに気付きましたが、C# でコーディングする方法がわかりません。JSON 形式のデータの読み取りと書き込みに使用できる、非常に優れた .net オープンソース ライブラリJson.NETがあることは知っています。
C# とJson.NETを Google AJAX Feed API で使用する方法を教えてもらえますか?
最終的解決:
public class FeedApiResult
{
public ResponseData responseData { get; set; }
public string responseDetails { get; set; }
public string responseStatus { get; set; }
}
public class ResponseData
{
public Feed feed { get; set; }
}
public class Feed
{
public string title { get; set; }
public string link { get; set; }
public string author { get; set; }
public string description { get; set; }
public string type { get; set; }
public List<Entry> entries { get; set; }
}
public class Entry
{
public string title { get; set; }
public string link { get; set; }
public string author { get; set; }
public string publishedDate { get; set; }
public string contentSnippet { get; set; }
public string content { get; set; }
}
var url = "http://ajax.googleapis.com/ajax/services/feed/load?q=http%3A%2F%2Fwww.digg.com%2Frss%2Findex.xml&v=1.0";
var wc = new WebClient();
var rawFeedData = wc.DownloadString(url);
//You can use System.Web.Script.Serialization if you don't want to use Json.NET
JavaScriptSerializer ser = new JavaScriptSerializer();
FeedApiResult foo = ser.Deserialize<FeedApiResult>(rawFeedData);
//Json.NET also return you the same strong typed object
var apiResult = JsonConvert.DeserializeObject<FeedApiResult>(rawFeedData);