Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a Stream into json value c#

Tags:

c#

json.net

I have below stream which I get from this line where req1 is of HttpResponseMessage type and responseMessage is of type Stream. How can I convert this Stream into a json Object. My end goal is to extract values from the specific keys in this json.

var responseMessage = await req1.Content.ReadAsStreamAsync();
like image 516
ZZZSharePoint Avatar asked May 24 '26 04:05

ZZZSharePoint


1 Answers

Above answer has a class defined. I didnt want to define different class as my model is dynamic. I found this solution , which worked well and got me the desired result

var serializer = new JsonSerializer();

            using (var sr = new StreamReader(responseMessage))
            using (var jsonTextReader = new JsonTextReader(sr))
            {
                var jsObj= serializer.Deserialize(jsonTextReader);
            }
like image 119
ZZZSharePoint Avatar answered May 26 '26 17:05

ZZZSharePoint