我在 WCF 服务中有两个类:
[DataContract]
public class item
{
[DataMember]
public string categoryid
{
get;
set;
}
[DataMember]
public string title
{
get;
set;
}
}
[DataContract]
public class Employee
{
[DataMember]
public string Id
{
get;
set;
}
[DataMember]
public string Name
{
get;
set;
}
}
我正在使用 LINQ 从数据集中获取数据:
public List<Employee> GetCities()
{
var em = ((from DataRow dr in ds.Tables["City"].Rows
select new
{
Id = dr["intCityId"].ToString(),
Name = dr["strTitle"].ToString()
}).Select(x => new Employee() { Id = x.Id, Name = x.Name}).ToList());
}
现在我通过返回这个值来获取 JSON 数据。此外,我也从项目类中获得了值,但现在我想将列表数据转换为 JSON 格式,如下所示:
{"content":{"em" :[{ "id" : "1","Name" : "name"},{ "id" : "2","Name" : "name2"}],
"item":[{"category":"Sports","Title":"Football"},{"category":"Sports1","Title":"Football2"}]}}
意思是我想将这两个类结果合并为一个,但上述格式是干净的 JSON 格式
请帮忙...