C# C用一个数组和一个布尔值反序列化Json字符串
我试图反序列化一个json字符串,但只有bool值附加到我的类中,因为数组值总是空的C# C用一个数组和一个布尔值反序列化Json字符串,c#,arrays,json,json.net,deserialization,C#,Arrays,Json,Json.net,Deserialization,我试图反序列化一个json字符串,但只有bool值附加到我的类中,因为数组值总是空的 public static EmployeeInformation GetEngineerAdditionInfo(ProjectUserRoles role) { EmployeeInformation engineerAdditionalInfo = new EmployeeInformation();
public static EmployeeInformation GetEngineerAdditionInfo(ProjectUserRoles role)
{
EmployeeInformation engineerAdditionalInfo = new EmployeeInformation();
var apiBaseUri = string.Empty;
apiBaseUri = "https:example.com";
Uri newUri = new Uri(apiBaseUri);
var httpWebRequest = (HttpWebRequest)WebRequest.Create(newUri);
httpWebRequest.Method = WebRequestMethods.Http.Get;
httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
using (var response = (HttpWebResponse)httpWebRequest.GetResponse())
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
string line = reader.ReadToEnd();
engineerAdditionalInfo = JsonConvert.DeserializeObject<EmployeeInformation>(line);
}
}
}
我错过什么了吗?或者有没有其他方法可以从json字符串获取数组列表
提前感谢,
迪内什。这只是一个猜测,但我想你忘了将你的员工基本细节公之于众:
public class EmployeeInformation
{
public bool IsSuccess { get; set; }
public List<EmployeeBasicDetails> EmployeeBasicDetails { get; set; }
}
public class EmployeeBasicDetails
{
public int UserId { get; set; }
public string EmployeeId { get; set; }
public string EmailId { get; set; }
public string EmployeeName { get; set; }
}
希望有帮助 EmployeeInformation中的EmployeeBasicDetails属性不是公共的。如果这是问题,请检查。非常感谢。你救了我一天..:它起作用了
{"IsSuccess":true,"EmployeeBasicDetails":[{"UserId":124,"EmployeeId":"SS124","EmailId":"example@example.com","EmployeeName":"Example"},{"UserId":125,"EmployeeId":"SS125","EmailId":"example@example.com","EmployeeName":"Example"},{"UserId":126,"EmployeeId":"SS126","EmailId":"example@example.com","EmployeeName":"Example"},{"UserId":127,"EmployeeId":"SS127","EmailId":"example@example.com","EmployeeName":"Example"}]}
public class EmployeeInformation
{
public bool IsSuccess { get; set; }
public List<EmployeeBasicDetails> EmployeeBasicDetails { get; set; }
}
public class EmployeeBasicDetails
{
public int UserId { get; set; }
public string EmployeeId { get; set; }
public string EmailId { get; set; }
public string EmployeeName { get; set; }
}