从WCF服务返回JSON

时间:2018-07-09 05:22:07

标签: json wcf

我要删除JSON中的第一和最后一个双引号,

public interface ITFSService
{
    [OperationContract]
    [WebInvoke(Method = "GET", UriTemplate = "TFS_GetProject", ResponseFormat = WebMessageFormat.Json)]
    string TFS_GetProject();     
}

我的返回方法是

public string TFS_GetProject()
{
    String json = String.Empty;
    try
    {
        DataTable dtbl = new DataTable();
        SqlDataAdapter da = new SqlDataAdapter("SELECT ProjectId, ProjectName, ProjectDescription ,ClientName ,Duration, "
            + " Manpower, ProjectStatus FROM TFS_mstrProject WHERE pStatus = 'Y'", con);
        con.Open();
        da.Fill(dtbl);
        con.Close();
        json = JsonConvert.SerializeObject(dtbl);
    }
    catch (Exception ex)
    {
        json = ex.Message.ToString();
    }
    return json;
}

我的回应就像

"[
    {
        \"ProjectId\":1.0,
        \"ProjectName\":\"Prematix Messanger - Android\",
        \"ProjectDescription\":\"Basically it  will be using for the internal communication of the office. this application mainly involves  message conversation and attaching doc for both sender and receiver.\",
        \"ClientName\":\"Prematix\",
        \"Duration\":15.0,
        \"Manpower\":4.0,
        \"ProjectStatus\":\"Locked\"
    }
]"

我认为这不是JSON格式。如何将其转换为JSON?

0 个答案:

没有答案