In this recipe, we will discuss how to properly use and consume REST services with Xamarin.iOS.
Create a new Single View Application in Xamarin Studio and name it ForecastApp
. In this recipe, we will use the Open Meteo Foundation REST API. The use of this API is subject to the terms of use stated in this page: http://openmeteofoundation.org/terms-of-use.
Perform the following steps to complete this recipe:
Add a label and a button on
ForecastAppViewController
. Make sure that the label's Lines property is set to at least three lines.Add the following code in the controller's
ViewDidLoad
method:this.btnForecast.TouchUpInside += async (sender, e) => { HttpClient client = new HttpClient(); string jsonResponse = await client.GetStringAsync("http://api.ometfn.net/0.1/forecast/eu12/46.5,6.32/now.json"); JsonValue jsonObj = JsonValue.Parse(jsonResponse); JsonArray tempArray = (JsonArray)jsonObj["temp"]; double temp = (double)tempArray...