我想使用Newtonsoft将C#对象序列化为JSON。我能够序列化带有属性的对象,但没有得到预期的JSON。我尝试使用layout属性,但没有为我工作。
期望的JSON:
[{"EmployeeID":100,"EmployeeName":"Pradeep","Layout":{"fillColor":function(rowIndex){return'#5d5e5f';},"hLineColor":function(i,node){return'#446b8e';}}}]
对象员工:
public class Employee
{
public int EmployeeID
{
get;
set;
}
public string EmployeeName
{
get;
set;
}
}
控制台类:
class Program
{
static void Main(string[] args)
{
List<Employee> lstemployee = new List<Employee>
{
new Employee()
{
EmployeeID = 100,
EmployeeName = "Pradeep",
}
};
string output = JsonConvert.SerializeObject(lstemployee);
Console.WriteLine(output);
Console.ReadLine();
}
}
它对于EmployeeID和EmployeeName属性正常工作。 我得到的JSON:
[{"EmployeeID":100,"EmployeeName":"Pradeep"}]
无法获取布局属性的JSON。预先感谢。
答案 0 :(得分:0)
以以下格式装饰有效载荷。 [ { “ EmployeeID”:100, “ EmployeeName”:“ Pradeep”, “布局”:{ “ fillColor”:“ function(rowIndex){return'#5d5e5f';}”, “ hLineColor”:“函数(i,node){return'#446b8e';}” } } ]