相关疑难解决方法(0)

为什么JSON.parse失败并带有空字符串?

为什么:

JSON.parse('');
Run Code Online (Sandbox Code Playgroud)

产生错误?

Uncaught SyntaxError: Unexpected end of input
Run Code Online (Sandbox Code Playgroud)

如果它刚刚归来,那不是更合乎逻辑null吗?

javascript json

61
推荐指数
2
解决办法
7万
查看次数

如何在asp net core 2.2中间件中多次读取请求正文?

我试过这个: 读取请求正文两次 ,这个:https : //github.com/aspnet/Mvc/issues/4962 但没有用。我这样阅读请求正文:

app.Use(async (context, next) =>
{
    var requestBody = await ReadStream(context.Request.Body);
    var requestPath = context.Request.Path.ToString();
    //Do some thing

    await next.Invoke();

    var responseStatusCode = context.Response.StatusCode;
    //Do some other thing
});

private async Task<string> ReadStream(Stream stream)
{
    using (var streamReader = new StreamReader(stream))
    {
        var result = await streamReader.ReadToEndAsync();

        return result;
    }
}
Run Code Online (Sandbox Code Playgroud)

在控制器中,我得到“处置对象”或“空流”。

c# middleware asp.net-core-2.2

11
推荐指数
2
解决办法
1万
查看次数

标签 统计

asp.net-core-2.2 ×1

c# ×1

javascript ×1

json ×1

middleware ×1