0

在使用 linq 解析和过滤后,如何将 JSON 数据添加到列表中?我只想将一些数据添加到列表中。

public class jsonData
{
    public List<rootelem> data { get; set; }
}

public class rootelem
{
    public List<employeeObj> employee { get; set; }
}

public class employeeObj
{
    public List<DataElement> empdetails { get; set; }
}

public class DataElement
{
    public ulong empid { get; set; }
    public string empname { get; set; }
    public string empdept { get; set; }
    public List<empphone> empphone { get; set; }
}

public class empphone
{
    public string home { get; set; }
    public string mobile { get; set; }
}
static void Main(string[] args)
{
    WebClient c = new WebClient();

    var jsonstring = @"{""data"":[{""employee"":[{""empdetails"":[{""empid"":""98977"",""empname"":""John"",""empdept"":""HR"",""empphone"":[{""home"":""868685768"",""mobile"":""89886654""}] }] }] }] }";

    jsonData myData = JsonConvert.DeserializeObject<jsonData>(jsonstring);

    foreach (var items in myData.data[0].employee[0].empdetails)
    {
        Console.WriteLine(items.empid);
        Console.WriteLine(items.empname);
        Console.WriteLine(items.empdept);
    }

      Console.ReadKey();

}
4

1 回答 1

0

你在找吗?

var myData = new JsonData
{
    Data = JsonConvert
             .DeserializeObject<List<rootelem>>(jsonstring)
             .Where(<your predicate>);
};
于 2013-09-22T08:43:31.480 回答