1

问题...我正在尝试通过 _bulk_docs API 将数据添加到 CouchDB。在大多数情况下,我有这个工作,但任何包含特殊字符(例如,我的数据中存在某些西班牙语或法语字符)的 JSON 值都会导致 CouchDB 给出“无效的 JSON”错误,并且数据被拒绝。

我不确定我需要设置什么才能使其正常工作。有什么建议么?CouchDB 似乎可以正确获取数据(至少它在其日志文件中看起来是正确的),但除非我删除特殊字符,否则它不会被处理。

4

2 回答 2

0

I'd try to debug the problem doing something like this:

  1. install on your machine a packet sniffer that understands http (e.g. wireshark) and launch it capturing packages sent to port 5984
  2. Create documents using curl from the command line:

    curl -X POST -d@test.js http://localhost:6984/testdb/_bulk_docs

    where test.js contains some documents with special characters. And see if this works as expected.

  3. do the same with the java library and see the differences in http headers and request body in the 2 cases.

NOTE: curl by default should send the data with content-type: application/x-www-form-urlencoded and this might be the problem, but check the headers because I'm not sure.

Hope this can help you.

于 2010-01-11T19:11:26.933 回答
0

content-type 应该是 application/json,而不是 test/plain

我不熟悉您的 JSON 解析器,但请确保它是 utf-8,仅仅因为您的 http 客户端库设置为 utf-8 并不意味着您的 json 序列化器正在输出 unicode。

于 2010-01-10T23:27:39.560 回答