Method to Convert from Stream to Json C#
Recently I was using the C# HttpClient to make REST request but I found that is was quite troublesome so I have changed to using HttpWebRequest instead.
So want the HttpWebRequest result is return it was in Stream form. I not able to convert it into Json.
this is the method i convert the stream to JSON.
If you have any question can leave a comment below.
So want the HttpWebRequest result is return it was in Stream form. I not able to convert it into Json.
this is the method i convert the stream to JSON.
HttpWebResponse response = (HttpWebResponse)requirejs.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader sr = new StreamReader(stream);
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
var jsonObject = serializer.DeserializeObject(sr.ReadToEnd());
As you can see that jsonObject is an object. Now you can parse it into the Json(JsonObject);If you have any question can leave a comment below.
Comments
Post a Comment