Konstantin Mokhov Konstantin Mokhov - 1 year ago 92
Javascript Question

get variable from json response

I have a GET function and response in JSON.
This is function:

contentType: 'application/json',
dataType: 'json',
success: function(msg){
var result = JSON.stringify(msg);
error: error,
type: 'GET',
url: myurl

success response from 'result' is like this

But when I try to get the 'name' from response, I get an error!
This is the error:

for(var k in result){

displays the letters

I tried this:

$.each(result,function(index, value){
console.log(index, value);

but always get error.

Answer Source

Try removing the JSON.stringify(msg.response). After which, msg.response.values[0].name should givejohn

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