【发布时间】:2015-06-20 22:38:01
【问题描述】:
我正在编写一个函数来使用 PhantomJS 从 CouchDB 中读取文档:
function getDocument(dbName, id) {
var dbPage = webpage.create();
dbPage.open('http://127.0.0.1:5984/' + dbName + '/' + id, function (status) {
console.log("GOT REPLY FROM SERVER:");
console.log(dbPage.content);
var foo = JSON.parse(dbPage.content);
//Do something with foo...
}
});
}
从 CouchDB (dbPage.content) 返回的内容如下所示:
GOT REPLY FROM SERVER:
<html><head></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">{"_id":"1","_rev":"1-3d3190e791500c179bdd02716add5280","myData": "d"]}
</pre></body></html>
剥离 html 以便我可以运行 JSON.parse 以获取表示文档的 javascript 对象的最佳方法是什么?
【问题讨论】:
标签: javascript couchdb phantomjs