【发布时间】:2014-05-26 09:45:45
【问题描述】:
我跟随 this 创建了 Restful Web 服务,将 JSON 显示为来自 MySQL 数据库的输出。
我成功完成了,但这里我在数据库中有近 100 个不同名称的表
为了获取数据,我正在使用这个:
ServiceContract]
public interface IService1
{
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "getAllCustomers")]
List<wsCustomer> GetAllCustomers();
还有这个:
public class Service1 : IService1
{
public List<wsCustomer> GetAllCustomers()
{
NorthwindDataContext dc = new NorthwindDataContext();
List<wsCustomer> results = new List<wsCustomer>();
foreach (Customer cust in dc.Customers)
{
results.Add(new wsCustomer() {
CustomerID = cust.CustomerID,
CompanyName = cust.CompanyName,
City = cust.City
});
}
return results;
}
我得到这样的数据输出:
{
"CustomerResult": [
{
"CustomerID ": "12124",
"CompanyName ": "http://www.google.com",
"City ": "xyz"
}
]
}
但是这里的问题在于每个结果我得到的表名结果就像我有另一个表一样
{
"UserResult": [
{
"UserID ": "12124",
"CompanyName ": "http://www.google.com",
"City ": "xyz"
}
]
}
So Here Insted Of CustomerResult 或 UserResult 我想要它作为 Result
有没有办法将其显示为所有表格的结果。
请给我建议..
【问题讨论】:
标签: c# mysql json web-services rest