CouchDB cURL Windows命令行JSON无效 [英] CouchDB cURL Windows Command Line Invalid JSON

查看:289
本文介绍了CouchDB cURL Windows命令行JSON无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用cURL从Windows命令行运行以下命令,尝试将新文档发布到现有CouchDB数据库(名为test)失败:

Running the following command from a Windows command line using cURL attempting to post a new document to an existing CouchDB database (named test) fails:

curl -H "Content-Type: application/json" -X POST "http://127.0.0.1:5984/test" -d {"valid":"json"}

它返回错误:

{"error":"bad_request","reason":"invalid_json"}



<是有效的,所以什么给了?

The JSON is valid so what gives?

推荐答案

答案与命令行上的JSON字符串的格式化有关。即使它是合适的JSON,当你键入它,命令行,似乎,在发送它之前必须重新格式化(可能有人可以解释为什么它这样做更详细。)要解决这个问题,你需要逃避你的报价命令行如下:

The answer is related to the formatting of the JSON string on the command line. Even though it is proper JSON when you type it, the command line, it seems, must reformat it before sending it.(Maybe someone else can explain why it does this in more detail.) To fix this you need to escape your quotations in the command line like so:

curl -H "Content-Type: application/json" -X POST "http://127.0.0.1:5984/test" -d {"""valid""":"""json"""}


b $ b

查看多余的引号?这应该工作,并返回ok:true与id和修订号。

See the extra quotation marks? This should work and return "ok:true" with an id and revision number.

这篇关于CouchDB cURL Windows命令行JSON无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆