fix: 修复空响应时无法正确反序列化的问题

This commit is contained in:
Fu Diwei
2021-12-13 17:13:25 +08:00
parent 66c9731d07
commit 7b0c793ae7
6 changed files with 18 additions and 18 deletions

View File

@@ -149,9 +149,9 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
where T : WechatTenpayResponse, new()
{
byte[] bytes = await flurlResponse.GetBytesAsync().ConfigureAwait(false);
bool jsonable = bytes.Length > 1 &&
(bytes[0] == 91 && bytes[bytes.Length - 1] == 93) || // "[...]"
(bytes[0] == 123 && bytes[bytes.Length - 1] == 125); // "{...}"
bool jsonable =
(bytes.Length > 1 && bytes[0] == 91 && bytes[bytes.Length - 1] == 93) || // "[...]"
(bytes.Length > 1 && bytes[0] == 123 && bytes[bytes.Length - 1] == 125); // "{...}"
T result = jsonable ? JsonSerializer.Deserialize<T>(Encoding.UTF8.GetString(bytes)) : new T();
result.RawStatus = flurlResponse.StatusCode;