web request and json no c#

Asked

Viewed 277 times

1

I am working with firebase, and I am searching the server data with Httpwebrequest, I was able to recover this data in the following way;

{"-L1od7ljenm8zhsps7ne":{"Age":"18 years","Name":"Lecturer","Telephone":"11 970705570"},"-L1odhpkmz_1zccfpzwf":{"Age":"10 years","Name":" ","Telephone":"98294792"},"-L1odmfc92yisdg4uxpu":{"Age":"30 years","Name":"Rune","Telephone":"98294792"}}

Using this code below;

HttpWebRequest pesquisar = (HttpWebRequest)WebRequest.CreateHttp(URL);
pesquisar.ContentType = "application/json: charset=utf-8";
HttpWebResponse pesquisar1 = pesquisar.GetResponse() as HttpWebResponse;
using (Stream pesquisarStream = pesquisar1.GetResponseStream())
{
    StreamReader reader = new StreamReader(pesquisarStream, Encoding.UTF8);

            var text = reader.ReadToEnd();

            richTextBox1.Text = text;
}

I would like to receive this data, directly in a json file and create a list so I can manipulate both the data and the Keys.

If anyone can help, thank you.

1 answer

3


When you use ReadToEnd() You go to the end of Stream and you don’t come back. If you really want to read all the content at once, store it in a variable and only then use it to manipulate in other places. When you call ReadToEnd() on the Console, it has already emptied the buffer.

See if this Document help you.

  • 1

    Could give an example of how to implement, it would greatly improve the response.

  • 2

    It’s like @Wilson did below.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.