31
rated 0 times
[
37]
[
6]
/ answers: 1 / hits: 32278
/ 9 Years ago, tue, september 29, 2015, 12:00:00
I have the following sample JSON and I would like to get the name of the column like Dribbble, Behance ...
{
status: 200,
success: true,
result:
[ { Dribbble: 'a',
Behance: '',
Blog: 'http://blog.invisionapp.com/reimagine-web-design-process/',
Youtube: '',
Vimeo: '' },
{ Dribbble: '',
Behance: '',
Blog: 'http://creative.mailchimp.com/paint-drips/?_ga=1.32574201.612462484.1431430487',
Youtube: '',
Vimeo: '' } ]
}
I'm using Request module and it returns JSON fine but I'm struggling to get the column name in string format. If I could get the column in number format at least, I would be able to know if it's the right column but I get two 0s instead.
request({
url: url,
json: true
}, function (error, response, body) {
if (!error && response.statusCode === 200) {
callback(body)
var json = body.result;
for (var key in json) {
if (json.hasOwnProperty(key)) {
var column = Object.keys(key);
console.log(column[0]);
}
}
}
})
More From » json