我有以下视图无法检索JSON值
{
"views" : {
"categories" : {
"map" : "function (doc) { emit(doc._id,{"title":doc.title,"parentnode":doc.parentnode});}"
}
}
}
即,对于每个文件,返回一个JSON对象,具有两个密钥:title
和parentnode
与它们各自的值。视图运行在cloudant UI
{
"id": "3bacce314363eb954f1922ff3cd2240c",
"key": "3bacce314363eb954f1922ff3cd2240c",
"value": {
"title": "poi",
"parentnode": "asd"
},
"_id": "3bacce314363eb954f1922ff3cd2240c"
}
这是完美就好了。现在,我尝试在我的Java程序作为
List<JSONObject> vals = cloudant.getViewRequestBuilder("categoryDesign", "categories")
.newRequest(com.cloudant.client.api.views.Key.Type.STRING, JSONObject.class)
.includeDocs(true)
.build()
.getResponse()
.getValues();
注意JSONObject
在这种情况下org.json.JSONObject;
阅读本。但是,为了这个,我得到
[{}]
所以后来我改变了看法有点
{
"views" : {
"categories" : {
"map" : "function (doc) { emit(doc._id,doc.title+":"+doc.parentnode);}"
}
}
}
,并在cloudant UI我看到
{
"id": "9db1f03e8f4d239a6e18d4612b1a4275",
"key": "9db1f03e8f4d239a6e18d4612b1a4275",
"value": "poi:asd",
"_id": "9db1f03e8f4d239a6e18d4612b1a4275"
}
,现在我做
List<String> vals = cloudant.getViewRequestBuilder("categoryDesign", "categories")
.newRequest(com.cloudant.client.api.views.Key.Type.STRING, String.class)
.includeDocs(true)
.build()
.getResponse()
.getValues();
现在,输出是
["poi:asd"]
我能做些什么来读取值为JSONObject
s?
跟进:如何从视图的输出中删除重复项?
谢谢!那工作。关于后续的任何想法? – AbtPst
查看最新答案 – markwatsonatx
非常感谢!这样可行 – AbtPst