0

给定以下示例数据:

[
    "this",
    1000,
    {
        "that": 1
    }
]

(根据 jsonlint.com,这是有效的 json)

data=json.loads('["this",1000,{"that":1}]')

当我尝试将该结构保存到 CouchDB 时,它会产生错误。

db['testdoc']=json.dumps(data)
ServerError: (400, ('bad_request', 'Document must be a JSON object'))

那么,我应该如何保存这种类型的结构?

我显然错过了一些重要的事情。

4

1 回答 1

1

根据这个网站:https ://wiki.apache.org/couchdb/Getting_started_with_Python ,简单地写:

data = json.loads('["this",1000,{"that":1}]')
db['testdoc'] = data

这里,data是一个经典的 Python 列表。

于 2014-05-04T13:12:39.907 回答