我是 MVC 中 WCFweb api WEB 服务的新手我使用 ADO.net 实体框架工作做了一个示例服务它以 XMl 格式返回结果我想要 Json 格式我写了这样的代码。
[WebGet(UriTemplate = "ListAccount", ResponseFormat = WebMessageFormat.Json)]
public IEnumerable<account> Get()
{
IEnumerable<account> objAcct = from cat in objEntity.accounts select cat;
List<account> Result;
Result = new List<account>();
foreach (account Account in objAcct)
{
account objAcc = new account();
objAcc.AccountNumber = Account.AccountNumber;
objAcc.AccountType = Account.AccountType;
objAcc.BusinessName = Account.BusinessName;
objAcc.AccountId = Account.AccountId;
objAcc.PrimaryContactFirstName = Account.PrimaryContactFirstName;
objAcc.PrimaryContactLastName = Account.PrimaryContactLastName;
objAcc.PrimaryContactEmail = Account.PrimaryContactEmail;
objAcc.PrimaryContactPhone = Account.PrimaryContactPhone;
objAcc.AccountGuid = Account.AccountGuid;
Result.Add(objAcc);
}
return Result.AsQueryable();
}
请帮助我如何获得 Json 格式的结果?