iam new to the wcf. iam developing wcf restful
iam returning string by serializing into json format by using the below code
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);
}
}
}
where iam getting the result as
"[{\"title\":\"Sathyam\",\"tid\":\"NiZamabad\"}]"
i want to get the result as
{"title":"Sathyam","tid":"Nizamabad"}
iam the operation contract and
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "MyGetData/{value}/{password}")]
Help me i tried bodystyle as wrapped also no