web request and json in c #

1

I'm working with firebase, and am fetching the data from the server with HttpWebRequest, I was able to recover this data as follows;

  

{"- L1OD7LjENM8ZHSpS7NE": {"Age": "18   years "," Name ":" vitor "," Telephone ":" 11   970705570 "}," - L1ODHPKmz_1zcCfpZwF ": {" Age ":" 10 years "," Name ":" joao   "," Phone ":" 9898294792 "}," - L1ODMFC92yisdG4UxPU ": {" Age ":" 30   years "," Name ":" bruno "," Phone ":" 9898294792 "}}

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 to manipulate both the data and the keys.

If anyone can help, thank you.

    
asked by anonymous 28.12.2017 / 16:58

1 answer

3

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

See if this Document help you.

    
28.12.2017 / 17:18