문제

I am currently using Redbranch-Hammock to interact with a CouchDB database. I am able to perform simple queries of CouchDB views but become unstuck when trying to add complex keys to the query and I believe this is to do with how Redbranch-Hammock uses JTokens to represent the start and end keys (via the To(..) and From(...) methods on the Query object).

For example, If I have the following URL:

localhost:5984/db/_design/doc/_view/count_by_tag?startkey=["hyundai"]&endkey=["hyundai",{}]

How would I represent the end key ["hyundai",{}] via a JToken object?

도움이 되었습니까?

해결책

If you're starting from the JSON string value and are trying to get a JToken from it, use JToken.Parse:

JToken token = JToken.Parse("[\"hyundai\",{}]");

Or, you can manually create a JToken that resolves to the JSON string ["hyundai",{}] like this:

JArray token = new JArray();
token.Add(new JValue("hyundai"));
token.Add(new JObject());

To convert a JToken to JSON, just use ToString:

string json = token.ToString(Formatting.None);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top