iam新增了wcf。 “:\” Sathyam IAM通过使用下面的代码如何在wcf中返回json格式
public string ConvertDataTabletoString()
{
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection("Data Source=mar-pc;database=user;User ID=sa;Password=123123;"))
{
using (SqlCommand cmd = new SqlCommand("select title=tname,tid=taddress from userdetails where userid='1'", con))
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
Dictionary<string, object> row;
foreach (DataRow dr in dt.Rows)
{
row = new Dictionary<string, object>();
foreach (DataColumn col in dt.Columns)
{
row.Add(col.ColumnName, dr[col]);
}
rows.Add(row);
}
return serializer.Serialize(rows);
}
}
}
其中IAM获得结果作为
“[{\” 标题\由序列化为JSON格式显影WCF宁静
IAM返回字符串\ “\ ”TID \“:\ ”尼扎马巴德\“}]”
我想要得到的结果作为
{ “称号”: “Sathyam”, “TID”: “尼扎马巴德”}
IAM承包经营和
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "MyGetData/{value}/{password}")]
帮助我,我试图bodystyle如裹也没有
但是您有'List'。那是你的输出。你为什么要改变它? –
2014-11-06 08:44:26
我想得到的输出为{“title”:“Sathyam”,“tid”:“Nizamabad”}所以我应该怎么做不知道如何输出将是 –
user2765331
2014-11-06 08:49:26