最好的重载方法匹配`RestSharp.Deserialize <rootobject>(RestSharp.IRestResponse)&#39;有一些无效的论点

时间:2015-05-04 18:08:14

标签: json xamarin.forms restsharp

所以我正在使用Xamarin表单上的这个项目,并在

的标题中得到错误
var rootObject = deserial.Deserialize<RootObject>(gameJson);

我应该将游戏列表返回给我的app.How我可以删除错误吗?

public async Task<Game[]> GetGamesAsync(){

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

                var apiKey = session ["ApiKey"];
                var userId = session ["UserId"];

                try
                {
                    request.AddHeader ("authenticationkey",apiKey.ToString ());
                    request.AddHeader ("authenticationid",userId.ToString ());
                } 
                catch{}

                IRestResponse response = client.Execute (request);
                statusCodeCheck (response);

                var gameJson = response.Content;

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

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


            }

1 个答案:

答案 0 :(得分:0)

不确定你是否在寻找这个,但我也在可移植的库中使用Restsharp并且我使用Json.NET的JsonConvert.DeserializeObject<T>反序列化数据交换 方法。我还没有遇到任何问题。

另一种可能的解决方案是返回的数据被包装,主对象不是RootObject