Forum Xamarin Xamarin.Forms

How can Xamarin.Forms class access JSON from REST WCF service?

vmhatupvmhatup Member
edited February 2019 in Xamarin.Forms

Hi,

I'm learning all about Xamarin.Forms, so please bear with me. This may seem like a simple question, but finding a solution has been an uphill battle.

This code snippet is from a class in my Xamarin.Forms project that loops through a json stream. I use the Newtonsoft library for the json:

string ar = string ar = "[{\"lon\":-66.105700,\"lat\":18.466333},{\"lon\":-65.827300,\"lat\":18.149683},{\"lon\":-65.961975,\"lat\":18.380102}]";
var obj = JsonConvert.DeserializeObject(ar);
string lat = string.Empty;
string lon = string.Empty;

foreach (var item in ((JArray)obj))
{
    lat = item.Value<string>("lat");
    lon = item.Value<string>("lon");
}

This works as expected.

Now, instead of being that string, it will be the string returned by calling URL http//IP/Service1.svc/GetTableData (the forum doesn't let me post URLs). This URL will return the same string format that was used in the snippet above:

"[{\"lon\":-66.105721,\"lat\":18.466333},{\"lon\":-65.827385,\"lat\":18.149683},{\"lon\":-65.961975,\"lat\":18.380102}]"

My question: How can my class in the Xamarin.Forms project call the URL and read the string being returned? I only have access to the URL, so I can't add it to my project as a service reference.

I'm using Visual Studio 2017.

Any help is appreciated.

Best Answer

Answers

  • vmhatupvmhatup Member

    Thanks.

Sign In or Register to comment.