这与标题为“带有 couchDB View 的“无效 JSON”错误,但 json 很好”的问题略有不同:我不是要上传文件,只是输入一个简单的文档。
我尝试使用的示例实际上来自 O'Reilly 的书“CouchDB:权威指南”,而且我很确定我之前已经尝试过并使其正常工作。这是命令:
curl -X PUT http://username:password@127.0.0.1:5984/albums/6e1295ed6c29495e54cc05947f18c8af -d '{"title":"There is Nothing Left to Lose","artist":"Foo Fighters"}'
数据库相册存在且用户名和密码正确。我已经用 JSONLint 检查了这个,JSON 是有效的,我不知所措......大概是 CouchDB 服务器本身存在问题,但它似乎运行正常......有什么想法吗?这让我发疯!
谢谢
请您参考如下方法:
谢谢你们。原来这是引号转义的问题。这是我从 CouchDB 用户邮件列表上的 David 那里得到的答案:
This is a windows thing regarding quoting - a real PITA. Unfortunately cmd.exe shell on windows doesn't parse this correctly. The rules for when escaping with a "" or a ^" or a \" are a bit vague but this works:
C:\tmp>curl -X PUT http://username:password@127.0.0.1:5984/albums/6e1295ed6c29495e54cc05947f18c8af -d "{\"title\":\"There is Nothing Left to Lose\",\"artist\":\"Foo Fighters\"}" {"ok":true,"id":"6e1295ed6c29495e54cc05947f18c8af","rev":"1-4b39c2971c9ad54cb37e08fa02fec636"}
C:\tmp>
"basically you need to \"escape\" all \"quotes\" within your JSON"
这解决了我的问题