How do I get the values available in Json format in my Xamarin application.
The code below is not returning anything.
public class MainActivity : Activity
{
ProgressDialog dialog;
TextView txtv1;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
txtv1 = FindViewById<TextView>(Resource.Id.txtResposta);
OlaRestAsync();//Chamada
}
private async Task OlaRestAsync()
{
var client = new HttpClient();
var json = await client.GetStringAsync($"https://api.hgbrasil.com/weather/?format=json&city_name=Ribeir%C3%A3o%20Preto&key=2857c531");
var dados = JsonConvert.DeserializeObject<HgWeather>(json);
txtv1.Text = dados.results.description;
}
}
Classes
public class HgWeather
{
public string by { get; set; }
public bool valid_key { get; set; }
public Results results { get; set; }
public float execution_time { get; set; }
public bool from_cache { get; set; }
}
public class Results
{
public int temp { get; set; }
public string date { get; set; }
public string time { get; set; }
public string condition_code { get; set; }
public string description { get; set; }
public string currently { get; set; }
public string cid { get; set; }
public string city { get; set; }
public string img_id { get; set; }
public string humidity { get; set; }
public string wind_speedy { get; set; }
public string sunrise { get; set; }
public string sunset { get; set; }
public string condition_slug { get; set; }
public string city_name { get; set; }
public Forecast[] forecast { get; set; }
}
public class Forecast
{
public string date { get; set; }
public string weekday { get; set; }
public string max { get; set; }
public string min { get; set; }
public string description { get; set; }
public string condition { get; set; }
}