Search code examples
cross-platformxamarin-studioxamarin.forms

How to get the json message from url using xamarin cross platform development?


How to get the json data from url using xamarin cross platform development.


Solution

  • private const string Url = "http://www.nactem.ac.uk/software/acromine/dictionary.py?sf={0}";
    public async Task<List<RootObject>> GetResult(string SearchString)
    {
        try
        {
            var client = new HttpClient();
            var json = await client.GetStringAsync(string.Format(Url, SearchString));
            return JsonConvert.DeserializeObject<List<RootObject>>(json.ToString());
        }
        catch (System.Exception exception)
        {
            return null;
        }
    }
    

    using HttpClient call url and getStrinAsyncc to get string from the url. using DeserializeObject to convert the string into json format. For refer more click here to see complete program in xamarin