mấy bác fix dùng em với w.name, w.id chạy xong nó vẫn = rỗng
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
namespace Integration3partyAPI
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
string IDup;
string Location;
public MainPage()
{
this.InitializeComponent();
}
private HttpClient client = new HttpClient();
private async Task DuLieuInput(object sender, RoutedEventArgs e)
{
client.BaseAddress = new Uri("http://localhost:55268/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
string DiaDiem = "ho chi minh";
string key = "177b2eb94701680dac9f9ba37bdaa58b";
HttpResponseMessage respon = await client.GetAsync("?q=" + DiaDiem + "&APPID=" + key);
if (respon.StatusCode == HttpStatusCode.OK)
{
ThongTinWeather w = respon.Content.ReadAsAsync<ThongTinWeather>().Result;
IDup = w.id;
Location = w.name;
}
}
private void btnUpdate_Click(object sender, RoutedEventArgs e)
{
txtID.Text += IDup;
txtDiaDiem.Text += Location;
}
}
}
namespace Integration3partyAPI
{
class ThongTinWeather
{
public string name { get; set; }
public string id { get; set; }
}
}