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

@ -122,9 +122,9 @@ namespace SKIT.FlurlHttpClient.Wechat.Ads
where T : WechatAdsResponse, 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();

View File

@ -111,9 +111,9 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
where T : WechatApiResponse, 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();

View File

@ -151,9 +151,9 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI
where T : WechatOpenAIPlatformResponse, 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();

View File

@ -128,9 +128,9 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI
where T : WechatOpenAIThirdPartyResponse, 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();

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;

View File

@ -112,9 +112,9 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
where T : WechatWorkResponse, 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();