gpt4 book ai didi

c# - “HttpClient”不包含 'GetFromJsonAsync' 的定义

转载 作者:行者123 更新时间:2023-12-03 21:10:29 25 4
gpt4 key购买 nike

我新建了一个 西装外套 应用程序,我想通过 访问 URL HttpClient
我遇到了这个错误

'HttpClient' does not contain a definition for 'GetFromJsonAsync' andno accessible extension method 'GetFromJsonAsync' accepting a firstargument of type 'HttpClient' could be found (are you missing a usingdirective or an assembly reference?) [BlazorApp]csharp(CS1061) ,


这是我的代码
 @inject HttpClient Http
<h1>@name</h1>
@code {
private string name;

protected override async Task OnInitializedAsync()
{
name = await Http.GetFromJsonAsync<string>("api/");
}
}

最佳答案

您需要添加以下 using 指令:

using System.Net.Http.Json;
GetFromJsonAsync is an extension method ,不属于 HttpClient本身。

关于c# - “HttpClient”不包含 'GetFromJsonAsync' 的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64134706/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com