Я пытаюсь отобразить и отобразить ответ на класс из Unirest с .NET. Я следовал этому примеру в стеке: Преобразование тела ответа http в формат JSON с использованием Unirest C #
Однако при запуске я получаю сообщение об ошибке «Невозможно привести объект типа« System.IO.MemoryStream »к типу« Root Object ». '
Мой код:
protected void Button1_Click(object sender, EventArgs e)
{
HttpResponse<JobSearchFeed.RootObject> jsonResponse = Unirest.get("http://api.indeed.com/ads/apisearch?publisher=PUBLISHER_KEY&v=2&l=California&q=javascript")
.header("X-Mashape-Key", "MY_KEY")
.header("Accept", "application/json")
.asJson<JobSearchFeed.RootObject>();
}
Я также осмотрелся и обнаружил, что мне нужно использовать это как «Задачу», но я не уверен, что это вообще захватывает какие-либо данные.
Мой код для этого:
static async Task<JobSearchFeed.RootObject> GetRootInfo()
{
HttpResponse<JobSearchFeed.RootObject> jsonResponse = await Unirest.get("http://api.indeed.com/ads/apisearch?publisher=PUBLISHER_KEY&v=2&l=California&q=javascript")
.header("X-Mashape-Key", "MY_KEY")
.header("Accept", "application/json")
.asJsonAsync<JobSearchFeed.RootObject>();
return jsonResponse.Body;
}
Мой класс:
public class JobSearchFeed
{
public class Result
{
public string jobtitle { get; set; }
public string company { get; set; }
public string city { get; set; }
public string state { get; set; }
public string country { get; set; }
public string language { get; set; }
public string formattedLocation { get; set; }
public string source { get; set; }
public string date { get; set; }
public string snippet { get; set; }
public string url { get; set; }
public string onmousedown { get; set; }
public string jobkey { get; set; }
public bool sponsored { get; set; }
public bool expired { get; set; }
public bool indeedApply { get; set; }
public string formattedLocationFull { get; set; }
public string formattedRelativeTime { get; set; }
public string stations { get; set; }
}
public class RootObject
{
public int version { get; set; }
public string query { get; set; }
public string location { get; set; }
public string paginationPayload { get; set; }
public int radius { get; set; }
public bool dupefilter { get; set; }
public bool highlight { get; set; }
public int totalResults { get; set; }
public int start { get; set; }
public int end { get; set; }
public int pageNumber { get; set; }
public List<Result> results { get; set; }
}
}