Rene Rene - 5 months ago 22
Javascript Question

Get Json object or loop

I have the following json.

{"sockets":{"16":true},"length":1}


I need to get the values of the sockets, already tried with loop and several other ways more can not. Can someone help me?

Already I tried so

$.each(json, function(idx, obj) {
alert(obj);
});

Answer
var obj= {"sockets":{"16":true},"length":1}

$.each( obj, function( key, value ) {
  alert(JSON.stringify(key) + ": " + JSON.stringify(value) );
});

codepen-http://codepen.io/nagasai/pen/ZOBgvK

Comments