Jeremy Miller Jeremy Miller - 1 year ago 75
Javascript Question

How can I easily have a javascript function to parse out specific objects from json string

I would like to pull out each of these fields and put them into a their own variable in javascript

"did": "00022B9A000000010001",
"ps": -1,
"hostName": "",
"ipAddress": ""

Answer Source

You seem to want something very very plain ...

var jsonString = '{"did": "00022B9A000000010001","ps": -1,"hostName": "zs-","ipAddress": ""}';
var obj = JSON.parse(jsonString);

var did = obj.did;
var ps =;
var hostName = obj.hostName;
var ipAddress = obj.ipAddress;

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download