最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Node.js dirty how do i get data from [Object object]? - Stack Overflow

programmeradmin0浏览0评论

How to i get the data from from [Object object]?

Here is an example of what i'm trying to do.

// Get data with dirty
var data = db.get('/htmltest')

// My test.db file
{"key":"foo","val":"barwhat?"}
{"key":"/htmltest","val":{"title":"Html Test","content":"<span>This is HTML</span>"}}


// the console.log gives me [Object Object]
// How do I get it to show the content of title (Html Test)
console.log(data);

How to i get the data from from [Object object]?

Here is an example of what i'm trying to do.

// Get data with dirty
var data = db.get('/htmltest')

// My test.db file
{"key":"foo","val":"barwhat?"}
{"key":"/htmltest","val":{"title":"Html Test","content":"<span>This is HTML</span>"}}


// the console.log gives me [Object Object]
// How do I get it to show the content of title (Html Test)
console.log(data);
Share Improve this question edited Feb 10, 2013 at 2:04 ThinkingStiff 65.4k30 gold badges147 silver badges241 bronze badges asked Oct 10, 2012 at 14:08 dasmikkodasmikko 7062 gold badges8 silver badges30 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

Another thing that you can do to help view your data for debugging is to use the util inspect function.

var util = require('util');
var data = db.get('/htmltest');

console.log(util.inspect(data));

Again, this is only useful for debugging and inspecting the contents of objects.

According to the documentation, the get method returns the value for a given key. In that case you should be able to access the title property like so:

// Get data with dirty
var data = db.get('/htmltest')

// My test.db file
{"key":"foo","val":"barwhat?"}
{"key":"/htmltest","val":{"title":"Html Test","content":"<span>This is HTML</span>"}}


// the console.log gives me [Object Object]
// How do I get it to show the content of title (Html Test)
console.log(data.title);

If you certify that your data variable is a JSON object, you can also parse easily it and show all content in one row using JSON.stringify(data);

发布评论

评论列表(0)

  1. 暂无评论