开发者

CouchDB and Special Characters

开发者 https://www.devze.com 2022-12-16 02:46 出处:网络
Question...I am trying to add data to CouchDB via the _bulk_docs API.For the most part I have this working, but any JSON value that contains a special character (e.g. certain Spanish or French c开发者

Question...I am trying to add data to CouchDB via the _bulk_docs API. For the most part I have this working, but any JSON value that contains a special character (e.g. certain Spanish or French c开发者_开发百科haracters exist in my data) results in an "invalid JSON" error given by CouchDB, and the data is rejected.

I'm not sure what I need to set in order to get this to work. Any suggestions? CouchDB seems to get the data properly (at least it looks correct in its log file), but it is not processed unless I remove the special chars.


content-type should be application/json, not test/plain

I'm not familiar with your JSON parser but make sure it's utf-8, just because your http client library is set to utf-8 doesn't mean your json serializer is outputing unicode.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号