问题
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