- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想解析 JSON 以使用 Flurl 列出。我的 JSON 数据是这样的。
{
"api": {
"results": 114,
"fixtures": {
"195": {
"fixture_id": "195",
"event_timestamp": "1543759500",
"event_date": "2018-12-02T14:05:00+00:00",
"league_id": "2",
"round": "Premier League - 14",
"homeTeam_id": "42",
"awayTeam_id": "47",
"homeTeam": "Arsenal",
"awayTeam": "Tottenham",
"status": "Match Finished",
"statusShort": "FT",
"goalsHomeTeam": "4",
"goalsAwayTeam": "2",
"halftime_score": "1 - 2",
"final_score": "4 - 2",
"penalty": null,
"elapsed": "87",
"firstHalfStart": "1543759500",
"secondHalfStart": "1543763100"
}
}}}
我也有这样的课。
class Fixture
{
//public string results { get; set; }
public string fixture_id { get; set; }
public string event_timestamp { get; set; }
public string event_date { get; set; }
public string league_id { get; set; }
public string round { get; set; }
public string homeTeam_id { get; set; }
public string awayTeam_id { get; set; }
public string homeTeam { get; set; }
public string awayTeam { get; set; }
public string status { get; set; }
public string statusShort { get; set; }
public string goalsHomeTeam { get; set; }
public string goalsAwayTeam { get; set; }
public string halftime_score { get; set; }
public string final_score { get; set; }
public string penalty { get; set; }
public string elapsed { get; set; }
public string firstHalfStart { get; set; }
public string secondHalfStart { get; set; }
}
我的代码在下面
try
{
string _url = string.Format("https://api-football-v1.p.mashape.com/fixtures/date/{0}",(DateTime.Now.Year+"-"+DateTime.Now.Month+"-"+DateTime.Now.Day).ToString());
//PERFORM IN BACKGROUND
await Task.Run(async () =>
{
var fixtures= await _url.WithHeader("Accept", "application/json").WithHeader("X-Mashape-Key", "g5vnMIqeChmshvK6H25VPavNCfhHp1KUtTkjsnOqEM06eP6cOd").GetJsonAsync<Fixture>();
});
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
我尝试使用 Flurl.HTTP 获取 JSON 数据。但是我有反序列化问题。我的错误在哪里?
如何在 C# 中将此 JSON 数据解析为 IList?
谢谢 friend 们的支持...
最佳答案
您基本上是在尝试选择 JSON 响应的内部部分,但您不能这样做 - 您需要反序列化为表示整个 响应的结构,然后遍历该结构以搞个人Fixture
.查看完整的响应主体,您需要再添加 2 个类来包含此结构:
public class ResponseBody
{
public Api api { get; set; }
}
public class Api
{
public int results { get; set; }
public Dictionary<string, Fixture> fixtures { get; set; }
}
然后调用GetJsonAsync<ResponseBody>()
而不是 GetJsonAsync<Fixture>()
.
关于flurl - 反序列化问题 GetJsonAsync<T> with Flurl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53601866/
我想解析 JSON 以使用 Flurl 列出。我的 JSON 数据是这样的。 { "api": { "results": 114, "fixtures": { "195
Asp.NET core 根据配置记录每个进入的请求。现在我想为我发送的 Flurl 请求提供相同的功能。最值得注意的是,我当然想知道请求何时失败或未完成。对于调试,我发现详细记录所有请求非常有帮助。
我在集成测试中使用 Flurl 并尝试配置客户端以记录响应(使用 Flurl.Http 3.0.0)。 我正在使用 event handlers以字符串形式读取响应,然后记录它。但是,如果调用代码使用
将 Blazor 从 0.5.1(使用工作 Flurl)更新到 0.6.0 后,通过 flurl 调用会引发异常: WASM: [Flurl.Http.FlurlHttpException] Call
在执行 ReceiveJson() 时,有什么方法可以映射不匹配的属性名称吗?例如,JSON 中的“user_name”应映射到 C# 对象中的“UserName”。 List people = aw
我试图将一些包含字符串数组的数据发布到端点,但收到错误“无效数组” 这样做: .PostUrlEncodedAsync(new { amount = 1000,
我有一个 .NET Core 2.0 WebApi 应用程序,我在其中将“Flurl.Http”(版本 2.1.0)NuGet 包添加到我的项目中。 我正在尝试使用 Flurl 对 Visual St
我是 Flurl 的新手。我正在尝试调用 api,我故意在参数中传递了无效的 apikey,然后 api 失败并显示“禁止”并显示错误代码 403。我如何在异常中处理它? public async
我正在尝试上传包含正文内容的文件。 PostMultipartAsync 是唯一的方法吗? 在我的 C# 后端代码中,我有这个: var resource = FormBind(); var file
您好,我正在使用 Flurl,我需要为帖子设置多个标题,网站上的文档说明要执行 await url.WithHeaders(new { h1 = "foo", h2 = "bar"}).GetJson
我正在制作一个客户端向服务器发出请求的应用程序。服务器使用 node.js 编写,客户端使用 flurl.Http 编写。 当服务器上的请求失败时,创建自定义错误消息总是有用的。像这样的: reque
我正在开发一个应用程序,我有一个使用Owin Token Bearer的后端服务器Azure API应用程序。我正在尝试登录到我的后端并像在我的网络客户端中一样取回 token 。我可以成功登录,但响
我从 Flurl 开始,我想创建一个 POST,但我认为我的 JSON 参数格式有问题。 可以看到JSON参数: { "aaaUser" : { "attributes" : {
我正在对正在运行的 Rest API 进行一些自动监视,我需要从 HttpResponseMessage 对象检索响应主体。我正在使用 Flurl Http:https://flurl.dev/doc
目录 简介 Url构建 Http 增强 HttpClient 管理 总结 简介 官方介绍,Flurl是一个现代的,流利的
我有一个使用依赖注入(inject)的 .NET HostedService。我的客户端工厂创建了一个策略处理程序,在 DI 中,我将 Flurl 配置为使用该工厂。在 Debug模式下,我可以看到客
我使用 Flurl 客户端有一个简单的发布请求,我想知道如何使用 IP、端口、用户名和密码等信息使用代理发出此请求。 string result = await atc.Request(url)
我目前同时使用 Polly 和 Flurl,但我有一个必须添加到每个请求的通用重试策略。我注意到 Polly 允许您使用 AddPolicyHandler(...) 设置默认值,但这需要一个 IHtt
我正在尝试对捕获 FlurlHttpException 的 Controller 进行单元测试并调用 GetResponseJson()在 catch block 中获取错误消息。我试图模拟异常,但是
我正在使用 Flurl访问需要基于证书的身份验证的 API。我从this SO post看到了将证书添加到 WebRequestHandler 并指示 HttpClient 使用此处理程序很容易。 但
我是一名优秀的程序员,十分优秀!