Using xamarin to retrieve JSON message from URl and show in table view

谁说胖子不能爱 提交于 2020-01-04 03:18:21

问题


I'm started developement in xamarin cross platform development in visual studio. I want to know, how to retrieve the JSON message from url to show the details in table view. Here i give a sample url, how to retrieve all the city name in the json data and show in table. Help me!

url: http://api.wunderground.com/api/02e5dd8c34e3e657/geolookup/conditions/forecast/q/Dhaka,Bangladesh.json


回答1:


As @Udi said, your question is too broad. But because of that, I'll give broad answers.

First, use HttpClient to retrieve the data from your url. Second, use Json.Net to deserialize your response into your entities/model.

string url = @"http://api.wunderground.com/api/02e5dd8c34e3e657/geolookup/conditions/forecast/q/Dhaka,Bangladesh.json";

using (var client = new HttpClient())
{
    var result = await client.GetStringAsync(url);
    return JsonConvert.DeserializeObject<YourModelForTheResponse>(result);
}

Third, to display your data, I would suggest going Xamarin.Forms or MonoTouch.Dialog. It makes using tables way easier.

I have a sample app that I queried a service, got a json response, and displayed the list of data using both Xamarin.Forms and MonoTouch.Dialog. Check out my sample app at github.




回答2:


I posted this question on xamarin forums with complete coding. I got a answer from someone with complete coding structure. Its work for me.

click here to see the link with question and answer. I hope, it works for all u.



来源:https://stackoverflow.com/questions/26606824/using-xamarin-to-retrieve-json-message-from-url-and-show-in-table-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!