将mashape api响应转换为c#类
我正在使用mashape api获取速度跟踪信息:- 由于这是在.NET c中,因此未遵守以下代码:-将mashape api响应转换为c#类,c#,.net,mashape,C#,.net,Mashape,我正在使用mashape api获取速度跟踪信息:- 由于这是在.NET c中,因此未遵守以下代码:- Task<HttpResponse<MyClass>> response = Unirest.get("https://indianpost.p.mashape.com/index.php?itemno=EF990403084IN") .header("X-Mashape-Key", mykey) .header("Accept", "application/json
Task<HttpResponse<MyClass>> response = Unirest.get("https://indianpost.p.mashape.com/index.php?itemno=EF990403084IN")
.header("X-Mashape-Key", mykey)
.header("Accept", "application/json")
.asJson();
Task response=Unirest.get(“https://indianpost.p.mashape.com/index.php?itemno=EF990403084IN")
.header(“X-Mashape-Key”,mykey)
.header(“接受”、“应用程序/json”)
.asJson();
complie错误是“无法从用法中推断方法‘unirest_net.request.HttpRequest.asJson()’的类型参数。请尝试显式指定类型参数。”
我不确定如何使用这个api。“MyClass”和什么有问题吗?RSDC-好的,结果是你的印度邮报API端点无论如何都不起作用。在Mashape上测试了它们,结果返回错误
>>我为metaCritic GET API找到了它,它不应该
MyClass
和RootObject
实际上是同一个类?@ArturoTorresSánchez嗨,我想你的想法是对的。我用你的想法+不同的API修改了我的答案,而且效果很好。至少现在是这样。我仍然有问题,但我会创造一个新的问题。谢谢。谢谢你的帮助,我会尽力让你知道它是怎么回事。顺便说一句,Mashape提供的语法是错误的。您显示的代码示例是一个异步调用,它缺少类类型。将最后一部分替换为:.asJsonAsync();-请参阅此处了解更多信息(异步部分)-但作为起点,您可以尝试下面的同步GET代码,以保持简单。德国劳埃德船级社。
public class MyClass
{
public class Result
{
public string name { get; set; }
public string score { get; set; }
public string url { get; set; }
public string rlsdate { get; set; }
public string rating { get; set; }
public string summary { get; set; }
public string platform { get; set; }
}
public class RootObject
{
public List<Result> results { get; set; }
}
}
HttpResponse<MyClass.RootObject> response = Unirest.get("https://byroredux-metacritic.p.mashape.com/game-list/ps4/coming-soon")
.header("X-Mashape-Key", "KxdVFN6Vlymshd5ezOQwBvS2Svjtp1bq5YOjsnFOkgTOwqwM6y")
.header("Accept", "application/json")
.asJson<MyClass.RootObject>();