Using xamarin to fetch JSON message from URl and display as table

I started doing xamarin cross platform development in visual studio. I want to know how to get a JSON message from a url to show the data as a table. Here I give a sample url how to get all city name in json data and show in table. Help me!

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

+3


source to share


2 answers


I posted this question on the xamarin forums with full coding. I got a response from someone with a complete coding structure. His job for me.



click here to see the link to the question and answer. Hope it works for everyone.

+3


source


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

First, use HttpClient to fetch data from your url. Second, use Json.Net to deserialize your response in 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, for displaying your data, I would suggest going to Xamarin.Forms or MonoTouch.Dialog . This makes tables easier to use.

I have a sample application where I requested a service, received a json response, and displayed a list of data using both Xamarin.Forms and MonoTouch.Dialog. Check out my example app on github .

+3


source







All Articles