无法在Xamarin studio中反序列化当前JSON数组(例如[1,2,3])

无法在Xamarin studio中反序列化当前JSON数组(例如[1,2,3]),json,xamarin,xamarin.forms,Json,Xamarin,Xamarin.forms,我在Xamarin窗体上运行iOS应用程序时出现此错误。 我正在使用WEB API,并试图在我的移动应用程序中显示该结果 我的Web服务方法是: public异步任务GetGamesAsync(){ var client=新的RestClient(“http://gams/GameStore2/"); var请求=新的重新请求(“api/Games”,Method.GET); request.OnBeforeDeserialization=resp=>{resp.ContentType=“app

我在Xamarin窗体上运行iOS应用程序时出现此错误。 我正在使用WEB API,并试图在我的移动应用程序中显示该结果

我的Web服务方法是:

public异步任务GetGamesAsync(){
var client=新的RestClient(“http://gams/GameStore2/");
var请求=新的重新请求(“api/Games”,Method.GET);
request.OnBeforeDeserialization=resp=>{resp.ContentType=“application/json”;};
var apiKey=Application.Current.Properties[“apiKey”];
var userId=Application.Current.Properties[“userId”];
试一试{
request.AddHeader(“key”,apiKey.ToString());
request.AddHeader(“id”,userId.ToString());
}
捕获{}
IRestResponse response=client.Execute(请求);
statusCodeCheck(响应);
Console.WriteLine(“此处”+response.Content);
var gameJson=response.Content;
if(response.StatusCode==HttpStatusCode.OK){
var rootObject=JsonConvert.DeserializeObject(gameJson);
返回rootObject.games;
}
否则{
返回null;
}
}
我的模型课是:

公共类游戏
{
public int GameId{get;set;}
公共字符串游戏名{get;set;}
公共日期时间释放日期{get;set;}
公共十进制价格{get;set;}
public int InventoryStock{get;set;}
公共布尔检查{get;set;}
公共列表类型{get;set;}
公共列表标记{get;set;}
}
公共类根对象{
公共游戏[]游戏{get;set;}
}

是否有任何帮助来修复此错误?

您正在多次反序列化响应。您也有冲突的返回类型<代码>列表和
根对象
。哪一个是正确的?您可以更改此行:

IRestResponse response = client.Execute <List<RootObject>>(request);
现在应该可以访问响应对象:

var games = response.Data.games;
var games = response.Data.games;