Quick way to get the contents of a MemoryStream as an ASCII string

前端 未结 2 1981
迷失自我
迷失自我 2021-02-13 23:15

I have a JSON string in a MemoryStream. I am using the following code to get it out as an ASCII string:

MemoryStream memstream = new MemoryStream(); 
/* Write a          


        
相关标签:
2条回答
  • 2021-02-14 00:00

    You could use the ToArray method:

    using (var stream = new MemoryStream())
    {
        /* Write a JSON string to stream here */
    
        string jsonString = Encoding.ASCII.GetString(stream.ToArray());
    }
    
    0 讨论(0)
  • 2021-02-14 00:03

    new StreamReader(memstream, Encoding.ASCII).ReadToEnd()

    0 讨论(0)
提交回复
热议问题