Returning JSON-formatted data from a WCF web service

Feedback

Question:

I have developed a WCF webservice that formats data using
returning json
. Here is my code:

String sJSONdata = "";
StreamReader reader = new StreamReader(data);
sJSONdata = reader.ReadToEnd();
//'now convert the JSON into a data table
DataTable dt = GetJSONTable(sJSONdata);
dt.TableName = "Customer";
Dictionary dict = new Dictionary();
foreach (DataRow rs in dt.Rows)
{
    dict = new Dictionary();
    foreach (DataColumn col in dt.Columns)
    {
        dict.Add(col.ColumnName, rs[col].ToString());
    }
}
return (new JavaScriptSerializer().Serialize(dict));

And I get the following output:

{
“SampleServiceResult”: “{“Id””:””1″”

Frequently Asked Questions

Posted in Uncategorized