How is the & symbol handled in the following query in oData?
/vendordataservice.svc/vDataMapper_SourceMapVendor?&$filter=startswith(ParentName,'AT&T')&$top=7&$skip=0
I'm using EF3.5 and SQL2008. When I send that to my oData service I get no data back.
Do not use the “JavaScript String replace() Method”. It will replace the first occurrence of the special characters. If you have 2 occurance of the same special characters in the filtering parameter, it will fail. So use the regular expression to replace the characters.
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;
}
Also pay attention, since the replacements also contains %
then %
itself should be replaced at the beginning
Here is a list of characters that should be encoded prior to sending to SQL server over HTTP:
http://msdn.microsoft.com/en-us/library/aa226544(SQL.80).aspx
Yes, the '&' symbol is one of them.
如果过滤器参数被视为一个单词,您可以在参数之前和之后附加单引号的 ASCII 值,如下所示%27AT&T%27
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.