在我正在开发的 .NET Core 2.1 Web API 上,我有一个 POST 方法,用于接收仅具有一个属性的 JSON 对象,如下所示:
\n\n{\n "longURL": "http://foo.example.com/path/path/path/path/path/pfad"\n}\nRun Code Online (Sandbox Code Playgroud)\n\n以及该方法的标头:
\n\npublic async Task<ActionResult<ShortenerOutputDto>> CreateAsync([FromBody] \nShortenerInputDto input)\nRun Code Online (Sandbox Code Playgroud)\n\n但如果输入 JSON 包含一些特殊字符,则会出现异常,如下所示:
\n\n{\n "longURL": "http://foo.example.com/path/path/path/path/path/pfad\xc2\xbf"\n}\nRun Code Online (Sandbox Code Playgroud)\n\n请注意,最后一个 (\xc2\xbf) 是有问题的字符。\n我得到的异常是:
\n\nSystem.Text.DecoderFallbackException: Unable to translate bytes [BF] at index 75 from specified code page to Unicode.\n at System.Text.DecoderExceptionFallbackBuffer.Throw(Byte[] bytesUnknown, Int32 index)\n at System.Text.DecoderExceptionFallbackBuffer.Fallback(Byte[] bytesUnknown, Int32 index)\n at System.Text.DecoderFallbackBuffer.InternalFallback(Byte[] bytes, Byte* pBytes, Char*& chars)\n at System.Text.UTF8Encoding.GetChars(Byte* bytes, Int32 byteCount, Char* chars, Int32 charCount, DecoderNLS baseDecoder)\n …Run Code Online (Sandbox Code Playgroud) 给出以下列表:
(TABLE1)
Expedient Amount
1 10
1 10
2 3
2 3
3 4
Run Code Online (Sandbox Code Playgroud)
我想计算不同权重的“金额”之和。因此,总和应为:
10 (from Expedient 1) +
3 (from Expediente 2) +
4 (from Expedient 3) =
10 + 3 + 4 = 17
Run Code Online (Sandbox Code Playgroud)
类似于此SQL语句:
Select SUM(Amount) from
(Select Distinct Expedient, Amount from TABLE1) DummyTable
Run Code Online (Sandbox Code Playgroud)