CouchDB and Special Characters

ぃ、小莉子 提交于 2020-01-05 05:57:06

问题


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 characters 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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/2036553/couchdb-and-special-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!