【发布时间】:2017-08-02 16:17:49
【问题描述】:
我有一个接受文件上传的 web api 服务。该文件的内容是一个小的 JSON 字符串,如下所示:
{ "name":"John", "age":31, "city":"New York" }
当它是一个流时,我如何获取文件内容,而不必将流作为文件保存在网络服务器上然后打开文件?
以下是我的sn-p:
byte[] fileData = null;
using(var binaryReader = new BinaryReader(httpRequest.Files[0].InputStream))
{
fileData = binaryReader.ReadBytes(httpRequest.Files[0].ContentLength);
}
我使用的是 4.0 .NET Framework
【问题讨论】:
-
问题是什么?
-
为什么不是
StreamReader? -
问题是如何从我的流中获取 JSON。
-
如果我使用 StreamReader,如何从我的流中获取 JSON?
标签: c# asp.net json file-io streamreader