javascript - Get column name from JSON -
i have following sample json , name of column 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 , returns json fine i'm struggling column name in string format. if column in number format @ least, able know if it's right column 2 0s instead.
request({ url: url, json: true }, function (error, response, body) { if (!error && response.statuscode === 200) { callback(body) var json = body.result; (var key in json) { if (json.hasownproperty(key)) { var column = object.keys(key); console.log(column[0]); } } } })
var json = { "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": '' } ] } // results (useful data) somewhere var results = json["result"]; // first result set, or can loop trhrough all, assuming each reuslt set same. if (results.length > 0){ var columnsin = results[0]; for(var key in columnsin){ console.log(key); // here column name looking } }else{ console.log("no columns"); }
this code snippet should point in proper direction
Comments
Post a Comment