這是我在asp.net web-api控制器中的代碼。從WebAPI操作方法返回單個元素而不是數組
[Route("~/GetLoginEmployeeInfo")]
public DataTable GetLoginEmployeeInfo()
{
DataTable dtUserInfo = new DataTable();
Hashtable htMenuList = new Hashtable();
htMenuList.Add("LoginKey", 20160636);
htMenuList.Add("Passkey", 123);
dtUserInfo = DataTableByCommandFromStoredProc("GetUserByIDAndPass", htMenuList);
return dtUserInfo; }
在WebApiConfig我有加:
config.Formatters.Remove(config.Formatters.XmlFormatter);
我已經得到了JSON作爲結果:[{"EmpID":"20160636","FullName":"Md Delower Hossain"}]
但我要的是以下:{"EmpID":"20160636","FullName":"Md Delower Hossain"}
括號[ ]應該爲我的編程目的而省略。我能做什麼?
linq首先或默認工作? return dtUserInfo.FirstOrDefault(); –