擅长:python、mysql、java
<p>Couch参数值是JSON文本,因此应该通过JSON编码值来创建。<em>然后</em>您还需要对结果进行URL编码,以适应标准URL。在</p>
<p>示例:</p>
<pre><code>import urllib, json
def to_json_query(params):
return urllib.urlencode({p: json.dumps(params[p]) for p in params})
>>> qs = to_json_query({'descending': True, 'startkey': 'Mexico', 'endkey': 'Mexico'})
'startkey=%22Mexico%22&endkey=%22Mexico%22&descending=%22true%22'
</code></pre>
<p>注意,我已经将<code>descending</code>的值改为一个boolean <code>True</code>,因为您需要一个JSON boolean<code>true</code>,而不是字符串{<cd4>}。在</p>
<p>(这里现有的答案假设字符串,而不是URL encode<em>或</em>JSON encode,因此对于任何JSON特殊字符或URL特殊字符、任何非ASCII或非字符串数据类型,都将失败。)</p>