I am trying to grab some values from my web api using HttpClient. I managed to get a true status
. However, I do not know how to grab values/read the JSON document. May I know if there's a way to do it?
I am currently doing in Xamarin.Forms in Visual Studio.
This is my code.
When I enter this URL into my browser, the document reads like this
{"d":[{"__type":"Info:#website.Model","infoClosingHours":"06:00:00 PM","infoID":1,"infoOpeningDays":"Monday","infoOpeningHours":"09:00:00 AM","infoStatus":"Open"}]}
xaml file
<Button Text="Grab Value" Clicked="GetData"/>
xaml.cs file
private void GetData(object sender, EventArgs e)
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("ipaddress");
// Add an Accept header for JSON format.
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
try{
HttpResponseMessage response = client.GetAsync("WebServices/information.svc/GetInformationJSON").Result;
HttpResponseMessage response1 = client.GetAsync("WebServices/information.svc/GetInformationJSON").Result;
}
catch
{
}
}