【发布时间】:2023-02-03 19:07:38
【问题描述】:
我正在使用 Newton Json 作为序列化对象。我想序列化一个具有两个属性的对象,一个是普通字符串,第二个属性是某些项目的字典。
我期待这样的结果:
"Company": {
"Id": "1393",
"emp1": {
"email": "test1@example.com",
"firstName": "test1",
"lastName": "test1",
"title": "Mr"
},
"emp2": {
"email": "test2@example.com",
"firstName": "test2",
"lastName": "test2",
"title": "Ms"
}
}
但我得到如下输出:
"Company": {
"Id": "1393",
"employees": {
"emp1": {
"email": "test1@example.com",
"firstName": "test1",
"lastName": "test1",
"title": "Mr"
},
"emp2": {
"email": "test2@example.com",
"firstName": "test2",
"lastName": "test2",
"title": "Ms"
}
}
}
这是我的代码:
public string GetCompany(Dictionary<string, Employee> employees)
{
var company = JsonConvert.SerializeObject(new
{
Id = "1393",
employees
});
return company;
}
【问题讨论】: