Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Unable to cast object of type 'RestSharp.JsonArray' to type 'System.Collections.Generic.IDictionary`

$
0
0

I get this error when i run my iOS application.

My webservice method is:
public async Task<Game[]> GetGamesAsync(){

            var client = new RestClient("http://gams/GameStore2/");
            var request = new RestRequest ("api/Games", Method.GET);
            request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; };

            var apiKey = Application.Current.Properties ["ApiKey"];
            var userId = Application.Current.Properties ["UserId"];

            try
            {
                request.AddHeader ("key",apiKey.ToString ());
                request.AddHeader ("id",userId.ToString ());
            } 
            catch{}

            IRestResponse response = client.Execute <List<RootObject>>(request);
            statusCodeCheck (response);
            Console.WriteLine ("here" + response.Content);
            //var gameJson =  response.Content;

            if (response.StatusCode == HttpStatusCode.OK) {

                RestSharp.Deserializers.JsonDeserializer deserial = new RestSharp.Deserializers.JsonDeserializer ();
                var rootObject = deserial.Deserialize<RootObject>(response);
                return rootObject.games;
            }
            else {
                return null;
            }


        }

My model class is:

   public class Game
    {
        public int GameId {get;set;}
        public string GameName { get; set; }
        public DateTime ReleaseDate { get; set;}
        public decimal Price { get; set;}
        public int InventoryStock { get; set;}
        public bool check { get; set;}
        public List<Genre> Genres { get; set;}
        public List<Tag> Tags { get; set;}
    }

        public class RootObject{
            public Game[] games { get; set;}
        }

Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>