C# 如何获得JSON格式的响应和请求?
我没有得到JSON格式的输出。这是密码 --IService1.cs-- --Service1.svc.cs-- --web.config-- 当我运行此服务时,我会将数据输入 但我希望结果是JSON格式的C# 如何获得JSON格式的响应和请求?,c#,.net,json,wcf,wcf-ria-services,C#,.net,Json,Wcf,Wcf Ria Services,我没有得到JSON格式的输出。这是密码 --IService1.cs-- --Service1.svc.cs-- --web.config-- 当我运行此服务时,我会将数据输入 但我希望结果是JSON格式的 示例:{currencycode:INR,DESCRIPTION:Indian Rupes,customercode:1001},….将[Serialize]属性添加到方法中 [ServiceContract] public interface IService1 { [Opera
示例:{currencycode:INR,DESCRIPTION:Indian Rupes,customercode:1001},….将[Serialize]属性添加到方法中
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "currency")]
List<Employee> GetAllEmployeesMethod();
[OperationContract]
string TestMethod();
[OperationContract]
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "players")]
List<Person> GetPlayers();
}
public List<Employee> GetAllEmployeesMethod()
{
List<Employee> mylist = new List<Employee>();
using (SqlConnection conn = new SqlConnection("--connection string--"))
{
conn.Open();
string cmdStr = String.Format("Select customercode,CurrencyCode,CurrencyDesc from Currency");
SqlCommand cmd = new SqlCommand(cmdStr, conn);
SqlDataReader rd = cmd.ExecuteReader();
if (rd.HasRows)
{
while (rd.Read())
mylist.Add(new Employee(rd.GetInt32(0), rd.GetString(1), rd.GetString(2)));
}
conn.Close();
}
return mylist;
}