C# 如何迭代JSON并输出到UITableViewCell?

C# 如何迭代JSON并输出到UITableViewCell?,c#,xamarin,C#,Xamarin,我正在尝试反序列化JSON并将值输出到UITableViewCell中。但它似乎从未击中我的foreach循环。我把一个断点放进去,它从来没有碰到它,我的loadingIndicator继续旋转 我的JSON是这样的:“年份”:“2012年”、“theMake”:“雪佛兰/GMC”、“theModel”:“雪崩1500四轮驱动”、“theEngine”:“5.3升V-8”、“极限”:“5000”、“注释”:“3.08轴比” 代码: string result = await content.Re

我正在尝试反序列化JSON并将值输出到UITableViewCell中。但它似乎从未击中我的foreach循环。我把一个断点放进去,它从来没有碰到它,我的loadingIndicator继续旋转

我的JSON是这样的:
“年份”:“2012年”、“theMake”:“雪佛兰/GMC”、“theModel”:“雪崩1500四轮驱动”、“theEngine”:“5.3升V-8”、“极限”:“5000”、“注释”:“3.08轴比”

代码

string result = await content.ReadAsStringAsync ();

var parsed = JsonConvert.DeserializeObject<TowInfo> (result);

//theTopInfo.Text = parsed.theYear + " " + parsed.theMake + " " + parsed.theModel;

foreach (var item in parsed.data) {

   Console.WriteLine(item.theEngine + " " + item.theTowLimit + " " + item.notes);

}

public class TowInfo
{
    public List<TowRatings> data { get; set;}

}

public class TowRatings
{
    public string theYear { get; set; }
    public string theMake { get; set; }
    public string theModel { get; set; }
    public string theEngine { get; set; }
    public string theTowLimit { get; set; }
    public string notes { get; set; }
}
string result=await content.ReadAsStringAsync();
var parsed=JsonConvert.DeserializeObject(结果);
//theTopInfo.Text=parsed.theYear+“”+parsed.theMake+“”+parsed.theModel;
foreach(parsed.data中的var项){
Console.WriteLine(item.theEngine+“”+item.theTowLimit+“”+item.notes);
}
公共类TowInfo
{
公共列表数据{get;set;}
}
公开课收视率
{
公共字符串年份{get;set;}
公共字符串theMake{get;set;}
公共字符串模型{get;set;}
公共字符串引擎{get;set;}
公共字符串towlimit{get;set;}
公共字符串注释{get;set;}
}

您是否已验证json是否被正确反序列化?json数据是否包含顶级“数据”元素?或者它只是一个拖带数组?如果没有括号,这是无效的,即使它有括号,它也是一个对象,所以你不能在一个对象上循环。如果反序列化工作正常,您只需要解析引擎等。当我将其添加到
列表中时,它不会到达断点,但当我将其设置为
var=parsed
时,它会到达断点<代码>列表parsed=JsonConvert.DeserializeObject>(结果)