How to query Couchbase using GetView StartKey and stringKey contains "&"

Im having problems querying Couchbase when the Startkey or EndKey contains “&” or “’”.
Im using .Net SDK 1.3.0

protected IView GetView(string name,
string startKey, string endKey,
int limit, bool isProjection = false)
{
string test = “Abercrombie & Fitch Company”;

return  _Client.GetView<T>(_designDoc, name, isProjection)
                                               .StartKey(test).EndKey(endKey).Limit(limit);

}

Error Msg:

bad_request. invalid UTF-8 JSON: {{error,insufficient_data},"\"Abercrombie “}”

I meant “&” and “’”

jarod -

Would you mind posting your design doc and view? It makes it “that” much easier to help :slight_smile:

You also may want to try url encoding your keys like this and see if it works:

string test = HttpUtility.UrlEncode( "Abercrombie & Fitch Company");

Thanks,

  • Jeff

I apologize to you sir…

{
“name”: “Abercrombie & Fitch Company”,
“isactive”: true,
“sysdate”: “2014-02-09T19:32:48”,
“type”: “company”
}
{
“name”: “Jason’s Store”,
“isactive”: true,
“sysdate”: “2014-02-09T19:32:48”,
“type”: “company”
}
{
“name”: “A.H. Belo Corporation”,
“isactive”: true,
“sysdate”: “2014-02-09T19:32:48”,
“type”: “company”
}

function (doc, meta) {
if (doc.type == “company” && doc.name) {
emit(doc.name, null);
}
}

protected IView GetView(string name, string startKey, string endKey, int limit, bool isProjection = false)
{
string test = “Abercrombie & Fitch Company”;
return _Client.GetView(_designDoc, name, isProjection).StartKey(test).EndKey(endKey).Limit(limit);
}

I updated my .Net Client to 1.3.3 and make sure Im using the correct version of Newtonsoft.
I get a different error below…

Cannot deserialize the current JSON array (e.g. [1,2,3]) into type…
because the type requires a JSON object (e.g. {“name”:“value”}) to deserialize correctly.
Newtonsoft.Json.JsonException {Newtonsoft.Json.JsonSerializationException}