在 oData 中的以下查询中如何处理 & 符号?

/vendordataservice.svc/vDataMapper_SourceMapVendor?&$filter=startswith(ParentName,'AT&T')&$top=7&$skip=0

我正在使用 EF3.5 和 SQL2008。当我将其发送到我的 oData 服务时,我没有收到任何数据。

有帮助吗?

解决方案 2

以下是在通过 HTTP 发送到 SQL 服务器之前应编码的字符列表:

http://msdn.microsoft.com/en-us/library/aa226544(SQL.80).aspx

是的,“&”符号就是其中之一。

其他提示

  

不要使用“JavaScript字符串替换()方法”。它将替换特殊字符的第一次出现。如果你有2 occurence在过滤参数相同的特殊字符,它就会失败。因此,使用正则表达式来替换字符。

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;
}

另外要注意,因为替代还包含然后% %它自应在开始更换

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top