以下のコードはwebRequestからの応答を取得しています。
HttpWebRequest request = WebRequest.Create(requestUrl) as HttpWebRequest;
using (var twitpicResponse = (HttpWebResponse)request.GetResponse())
{
using (var reader = new StreamReader(twitpicResponse.GetResponseStream()))
{
JavaScriptSerializer js = new JavaScriptSerializer();
var objText = reader.ReadToEnd();
while (reader.EndOfStream)
{
objText = reader.ReadLine();
MyObject myobj= (MyObject)js.Deserialize<MyObject>(objText);
}
}
}
以下の形式で JSON 応答を取得しています。この JSON 応答を myobj にバインドしたいと考えています。
{"Results":[{"Id":"571611","ModerationStatus":"APPROVED","LastModificationTime":
"2011-10-31T05:36:33-05:00"
,"IsRatingsOnly":true,"TotalCommentCount":0,"Rating":5,"RatingRange":5,"IsRecommended":true,"TotalFeedbackCount":0,"TotalPositiveFeedbackCount":0,"TotalNegativeFeedbackCount":0,"DisplayLocale":"en_US","SubmissionTime":
"2011-05-25T00:00:00-05:00"
,"IsFeatured":false,"LastModeratedTime":
"2011-10-31T05:36:33-05:00"
,"ProductId":"3240234","AuthorId":"z7knrbjunvi022pe4swqp18fra"},{"Id":"571612","ModerationStatus":"APPROVED","LastModificationTime":
"2011-10-31T05:36:33-05:00"
,"IsRatingsOnly":true,"TotalCommentCount":0,"Rating":5,"RatingRange":5,"IsRecommended":true,"TotalFeedbackCount":0,"TotalPositiveFeedbackCount":0,"TotalNegativeFeedbackCount":0,"DisplayLocale":"en_US","SubmissionTime":
"2011-05-25T00:00:00-05:00"
,"IsFeatured":false,"LastModeratedTime":
"2011-10-31T05:36:33-05:00"
,"ProductId":"3240234","AuthorId":"zsknvekklaxl56nzwliultz5mp"}],"Includes":{"Products":{"3240234":{"Id":"3240234","Name":"Rosner Chevrolet","Description":"Brevard County","BrandExternalId":"01","Brand":{"Id":"01","Name":"Personal Accounts"},"CategoryId":"324","ProductPageUrl":"https://www.sccu.com/personal/vehicle-loans/dealer-review.asp?did=234&dealerName=Rosner+Chevrolet"}},"Authors":{"z7knrbjunvi022pe4swqp18fra":{"Id":"z7knrbjunvi022pe4swqp18fra","ModerationStatus":"NONE"},"zsknvekklaxl56nzwliultz5mp":{"Id":"zsknvekklaxl56nzwliultz5mp","ModerationStatus":"NONE"}}},"HasErrors":false,"Offset":0,"Limit":2,"TotalResults":25}
この JSON ブロック (複数の値を持つこの JSON ブロック) を 1 つずつ読み取り、objectlist に格納します。