我创建了一个可以接受一个字符串参数的API,但是当我尝试将""
用作searchterm
时,输出结果会有一个转义字符。我该如何删除?谢谢
searchterm = searchterm.Replace(@"\", String.Empty);
我尝试了这个,但是仍然有转义符。
这是我的代码c#
public static JToken getRelatedKeywordsApiSpTable(string searchterm)
{
JObject results = new JObject();
searchterm = searchterm.Replace(@"\", String.Empty);
DataSet ds = SearchData.getRelatedKeyword(searchterm);
DynamicCollabObject relatedkeywords = new DynamicCollabObject(ds);
results.Add("RelatedKeywords", relatedkeywords.dobject);
return results;
}
public static DataSet getRelatedKeyword(string searchterm)
{
List<SqlParameter> parameters = new List<SqlParameter>();
parameters.Add(new SqlParameter("@st", searchterm));
return SQLDAL.runSPWithParams(SearchSPs.getRelatedKeywordApi, parameters, SearchSettings.badlands);
}
这是我的终点
[HttpGet]
[Route("relatedkeyword/{searchterm}")]
public IHttpActionResult RelatedKeywordApiTable(string searchterm)
{
return Ok(SearchBusiness.getRelatedKeywordsApiSpTable(searchterm));
}
我的SP
select top 20 relatedkeyword as Keyword, [count] as [Count]
from Transform_DIM_RelatedKeyword_Count WITH (NOLOCK)
where searchterm=@st
order by count desc
输出:
{
"RelatedKeywords": [
{
"Keyword": "\"\"",
"Count": 7
}
]
}
我的期望应该看起来像实际的输入搜索词