如何从JSON数组中提取数据

时间:2017-01-18 22:57:00

标签: c#

我需要一些指导,我的代码工作正常,直到我尝试将前轮胎宽度映射到标签!!

如何访问下面的JSON数组代码?

以下代码

public class DVLA
{

    public List<DVLAVehicle> cast { get; set; }

}


public class DVLAVehicle
{
    [JsonProperty(PropertyName = "make")]
    public string make { get; set; }

    [JsonProperty(PropertyName = "model")]
    public string model { get; set; }

    [JsonProperty(PropertyName = "year")]
    public int year { get; set; }

    [JsonProperty(PropertyName = "frontTyres")]
    public frontTyres[] frontTyres { get; set; }

    [JsonProperty(PropertyName = "rearTyres")]
    public rearTyres[] rearTyres { get; set; }


}

public class frontTyres
{
    public int width { get; set; }
    public int ratio { get; set; }
    public string rim { get; set; }
    public string speedRating { get; set; }
    public int psi { get; set; }
    public int loadIndex { get; set; }

}

var v1 = JsonConvert.DeserializeObject(TyreDetails);

                lblmake.Text = v1.make;
                lblmodel.Text = v1.model;
                lblyear.Text = v1.year.ToString();

                lblwidth.Text = v1.frontTyres.Width;

0 个答案:

没有答案