mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-16 01:41:14 +08:00
30 lines
1013 B
C#
30 lines
1013 B
C#
using System;
|
|
using System.Net.Http;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AntBlazor
|
|
{
|
|
public static class HttpClientExtensions
|
|
{
|
|
public static async ValueTask<T> GetJsonAsync<T>(this HttpClient httpClient, string url)
|
|
{
|
|
var s = await httpClient.GetStreamAsync(url);
|
|
return await JsonSerializer.DeserializeAsync<T>(s, options: new JsonSerializerOptions()
|
|
{
|
|
PropertyNameCaseInsensitive = true,
|
|
ReadCommentHandling = JsonCommentHandling.Skip
|
|
});
|
|
}
|
|
|
|
public static async ValueTask<T> GetJsonAsync<T>(this HttpClient httpClient, Uri url)
|
|
{
|
|
var s = await httpClient.GetStreamAsync(url);
|
|
return await JsonSerializer.DeserializeAsync<T>(s, options: new JsonSerializerOptions()
|
|
{
|
|
PropertyNameCaseInsensitive = true,
|
|
ReadCommentHandling = JsonCommentHandling.Skip
|
|
});
|
|
}
|
|
}
|
|
} |