在使用 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();
}