I want to Deserialize JSON into Object but I don\'t want to Deserialize nested JSON, nested of nested JSON should convert into JSON list (Please check \"My expected
I think you will have to rebuild your list of Employees :
RootObject Employees = JsonConvert.DeserializeObject(jsonEmployees);
List EmployeesNew = new List();
foreach (var item in Employees.Employees)
{
string StringAddress = JsonConvert.SerializeObject(item.Address, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
EmployeesNew.Add(new Employee { EmpId = item.EmpId, EmpName = item.EmpName, AddressString = StringAddress });
}
Your class:
public class Employee
{
public int EmpId { get; set; }
public string EmpName { get; set; }
// **Note** : I'm not using List data type for Address, instead of I want list of address in JSON string
public List Address { get; set; }
public string AddressString { get; set; }
}
public class RootObject
{
public List Employees { get; set; }
}
public class AddressItems
{
public int AddressId { get; set; }
public string Address { get; set; }
}