Thursday 29 November 2018

JSON parse

I want to find the number of 'ip' or keys in a json return. I have a function :getHostMatchRuleCount(ruleID, function (count) { }); function getHostMatchRuleCount(ruleID, eventCallback) { CT.getHostMatchRule(CT.options, ruleID, function(hosts) { console.log(hosts) var count = Object.keys(hosts).length; console.log(count); eventCallback(count); }); } Which returns:{ hosts: [ { hostId: 167772246, ip: '10.0.0.86', mac: '10ddb1ece7eb', _links: [Object] }, { hostId: 167772220, ip: '10.0.0.60', mac: '041e64edb10f', _links: [Object] } ] } 1 <--------- I expect the count to be two, as there are two entries.Any ideas?thanks!

Submitted November 30, 2018 at 03:35AM by Jacksonp2008

No comments:

Post a Comment