G Mehdi Balti
G Mehdi Balti

Reputation: 164

Parsing API response in Xamarin form

I am new to xamarin. I am trying to get data from php api but it doesn't give me any data or error kindly check. URL is
http://mehdibalti.000webhostapp.com/xamrin/getall.php

response is .. [{"Id":"1","Name":"Mehdi","Department":"Balti"},{"Id":"2","Name":"Mehdi","Department":"Syntecx"}]

and i did like this 



  public class EmployeeServices
    {
        public EmployeeServices()
        {
        }


        public async Task<List<EmployeeModel>>  getEmployeeAsyn(){




            RestClient<EmployeeModel> resclient = new RestClient<EmployeeModel>();

            var list =await resclient.GetTodoItemsAsync();
            return list;

        }

    }
}

this is my resClient Class

        public async Task<List<EmployeeModel>> GetTodoItemsAsync()
        {

            var httpClient = new HttpClient();


            var response = await httpClient.GetStringAsync(getAllUrl);


            response = response.Replace("\"", "");


            var todoItems = JsonConvert.DeserializeObject<List<EmployeeModel>>(response);



            return todoItems;

        }

this is Model class public class EmployeeModel

{

    public string Id { get; set; }
    public string Name { get; set; }

    public string Department { get; set; }
}


but it did not return any list

Upvotes: 0

Views: 50

Answers (1)

Nick Kovalsky
Nick Kovalsky

Reputation: 6452

The result API is giving you is not a list. Use stuff like http://json2csharp.com/ to investigate json you are getting.

Upvotes: 1

Related Questions