&在oData中的以下查询中处理的符号?
/vendordataservice.svc/vDataMapper_SourceMapVendor?&$filter=startswith(ParentName,'AT&T')&$top=7&$skip=0
我正在使用EF3.5和SQL2008。当我将它发送到我的oData服务时,我没有得到任何数据。
答案 0 :(得分:5)
不要使用“JavaScript String replace()方法”。它将替换第一次出现的特殊字符。如果过滤参数中有2个相同的特殊字符,则会失败。因此,使用正则表达式替换字符。
function replaceSpecialCharacters(attribute) {
// replace the single quotes
attribute = attribute.replace(/'/g, "''");
attribute = attribute.replace(/%/g, "%25");
attribute = attribute.replace(/\+/g, "%2B");
attribute = attribute.replace(/\//g, "%2F");
attribute = attribute.replace(/\?/g, "%3F");
attribute = attribute.replace(/#/g, "%23");
attribute = attribute.replace(/&/g, "%26");
return attribute;
}
另外要注意,因为替换还包含%
然后%
它应该在开头替换
答案 1 :(得分:3)
以下是在通过HTTP发送到SQL Server之前应编码的字符列表:
http://msdn.microsoft.com/en-us/library/aa226544(SQL.80).aspx
是的,'&'符号就是其中之一。
答案 2 :(得分:0)
如果将filter参数视为一个单词,则可以像这样%27AT&T%27