0

I want to use httpresponse as json object so that i use the values in it for example internalid,itemid etc i am getting httpresponse and able to make stream of it but this is not working for me because it will return string

1- in response i am getting JSON string 2- I have tried to parse with JSONConvert method 3- I Got httpresponse with StreamReader and able to display response string in console.

[WebResponse response = request.GetResponse();            
HttpWebResponse httpResponse = (HttpWebResponse)response;
Console.WriteLine("Content length is {0}", httpResponse.ContentLength);
Console.WriteLine("Content type is {0}",httpResponse.ContentType);         
var response1 = (HttpWebResponse)request.GetResponse();
var rawJson = new StreamReader(response1.GetResponseStream()).ReadToEnd();
Console.WriteLine(rawJson);][1]

This code mentioned above return "string" i want to use this like "object"

humza riaz
  • 11
  • 2

1 Answers1

1

You can parse to a dynamic using Newtonsoft: Deserialize json object into dynamic object using Json.net

Alternatively, deserialize to a strongly typed object. To generate the object model, you have various options:

https://visualstudiomagazine.com/Blogs/Tool-Tracker/2018/02/paste-json-and-xml-as-class.aspx

https://app.quicktype.io/#l=cs&r=json2csharp

Matt Evans
  • 7,113
  • 7
  • 32
  • 64