关于带有ouchDB视图的“无效JSON”的错误,但JSON正常 [英] Error about 'invalid JSON' with couchDB view but the json's fine

查看:109
本文介绍了关于带有ouchDB视图的“无效JSON”的错误,但JSON正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在CouchDB上设置以下视图

I am trying to setup the following view on CouchDB

{
"_id":"_design/id",
"_rev":"1-9be2e55e05ac368da3047841f301203d",
"language":"javascript",
    "views":{ "by_id":{
              "map" : "function(doc) { emit(doc.id, doc)}"
        },"from_user_id":{
            "map" : "function(doc) { if (doc.from_user_id) {emit(doc.from_user_id, doc)}}"},
        "from_user":{
            "map" : "function(doc) { if (doc.from_user) {emit(doc.from_user, doc)}}"},
        "to_user_id":{
            "map" : "function(doc) {if (doc.to_user_id){ emit(doc.to_user_id, doc)}}"},
        "to_user":{
            "map" : "function(doc) {if (doc.to_user){ emit(doc.to_user, doc)}}" },
        "max_id":{
         "map" : "function(doc) { if (doc.id) {emit(doc._id, eval(doc.id))}}",  
         "reduce" :"function(key,value) { a = value[0]; for (i=1; i <value.length; ++i){a =    Math.max(a,value[i])} return a}"
        }
    }
}

尝试使用curl'PUT'这个:

when I try to 'PUT' this using curl:

 curl -X PUT -d keys.json  $CDB/_design/id
 {"error":"bad_request","reason":"invalid UTF-8 JSON"}

我知道它不是无效的JSON,因为我使用Python 2.6中内置的 json库对其进行了测试,因此可以很好地加载。 JS螺丝钉给我错误必须对函数求值

I know it's not invalid JSON, because I tested it using the 'json' library built into Python 2.6, it loads fine. JS screw ups give me the error 'must evaluate to a function'

我已经用od检查了文件,没有隐藏的控制字符,我的系统设置为UTF -8。我正在使用CouchDB版本0.10.1

I have checked the file with od, there are no hidden control chars, my system is set to UTF-8. I'm using CouchDB version 0.10.1

还有什么问题呢?

推荐答案

@titanoba提示该问题:

@titanoba hinted at the problem:

-d curl选项期望将实际数据作为参数!

The -d option of curl expects the actual data as the argument!

如果要在文件中提供数据,则需要在其前面加上 @

If you want to provide the data in a file, you need to prefix it with @:

curl -X PUT -d @keys.json  $CDB/_design/id

这篇关于关于带有ouchDB视图的“无效JSON”的错误,但JSON正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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