在我的一個應用程序中,我收到了webrequest的響應。這項服務是RESTful服務,將返回類似下面的JSON格式結果:閱讀HttpwebResponse json響應,C#
{
"id" : "1lad07",
"text" : "test",
"url" : "http:\/\/twitpic.com\/1lacuz",
"width" : 220,
"height" : 84,
"size" : 8722,
"type" : "png",
"timestamp" : "Wed, 05 May 2010 16:11:48 +0000",
"user" : {
"id" : 12345,
"screen_name" : "twitpicuser"
}
}
這裏是我當前的代碼:
byte[] bytes = Encoding.GetEncoding(contentEncoding).GetBytes(contents.ToString());
request.ContentLength = bytes.Length;
using (var requestStream = request.GetRequestStream()) {
requestStream.Write(bytes, 0, bytes.Length);
using (var twitpicResponse = (HttpWebResponse)request.GetResponse()) {
using (var reader = new StreamReader(twitpicResponse.GetResponseStream())) {
//What should I do here?
}
}
}
我怎樣才能讀取響應?我想要的網址和用戶名。
這可能是一個好主意,檢查出Restsharp做你的休息服務電話https://github.com/johnsheehan/RestSharp/wiki/Getting-Started將使你的生活100000x更容易沿着軌道,你可以設置對象模型進行解碼。 – anthonyvscode 2011-03-31 00:24:09