Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
向CouchBase Lite Android添加Json字符串_Android_Couchbase_Couchbase Lite - Fatal编程技术网

向CouchBase Lite Android添加Json字符串

向CouchBase Lite Android添加Json字符串,android,couchbase,couchbase-lite,Android,Couchbase,Couchbase Lite,我是Couchbase Mobile的新手,我正在尝试添加下面在db中显示的json字符串,但无法实现。通过添加,我的意思是基于这个json创建一个文档,然后将这个文档添加到db中 { "array": [ 1, 2, 3 ], "boolean": true, "null": null, "number": 123, "object": { "a": "b", "c": "d", "e": "f" }, "stri

我是Couchbase Mobile的新手,我正在尝试添加下面在db中显示的json字符串,但无法实现。通过添加,我的意思是基于这个json创建一个文档,然后将这个文档添加到db中

{
  "array": [
    1,
    2,
    3
  ],
  "boolean": true,
  "null": null,
  "number": 123,
  "object": {
    "a": "b",
    "c": "d",
    "e": "f"
  },
  "string": "Hello World"
}

CouchDB存储以json表示的文档。 要将json字符串添加到文档中,请添加一个“_id”属性,该属性将字符串作为文档的名称。在本例中,我将此文档称为“my_json”

然后使用您拥有的任何http库(我将使用
curl
实用程序)将json发布到数据库中

curl -X POST -H "Content-Type: application/json" -d '{"_id": "my_json", "array":[1,2,3], "boolean": true, "null": null,"number": 123, "object": {"a": "b","c": "d", "e": "f"},"string": "Hello World"}' "http://localhost:5984/example"
这将创建一个名为“my_json”的文档,该文档位于本地主机端口5984上运行的服务器的“示例”数据库中

然后,您应该从服务器获得如下响应:

{"ok":true,"id":"my_json","rev":"1-03c9094bea172b21e23502b82cc6e7ca"}
(您的“版本”编号将不同。)


有关CouchDB的http api的更多信息,请参阅或。

谢谢您的回复,但这对我来说不起作用,因为我的CouchDB在我的Android应用程序中,我也没有地方运行此命令。CouchDB和couchbase是两个完全不同的东西。你用的是哪一款?很抱歉我用的是Couchbase lite手机