我使用Xamarin开发移动应用程序
我需要做些什么才能打印从网络服务中获取的数据
Json Formated
异步功能
public async Task<List<MesajModel>> MesajAl()
{
MesajModel obj =new MesajModel();
List<MesajModel> mesaj =new List<MesajModel>();
string url = "https://jsonplaceholder.typicode.com/posts/1";
try
{
HttpClient cl = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, url);
HttpResponseMessage response = await cl.SendAsync(request);
HttpContent content = response.Content;
var statusCode = response.StatusCode;
string json = await content.ReadAsStringAsync();
obj.Aciklama = json.ToString();
obj.Mesaj = "Yaptik";
mesaj.Add(obj);
return mesaj;
}
catch (Exception e)
{
return mesaj;
}
}
我想要触发的功能 单击按钮的Xamarin.Form事件
private void Button_Clicked(object sender, EventArgs e)
{
var a=con.MesajAl().Wait();
}