Nicoleta Wilskon Nicoleta Wilskon - 3 months ago 13
AngularJS Question

Handling key value pair in response

I have the following response.

response: {
"json": {
"response":{
"servicetype":"",
"functiontype":"",
"statuscode":"0",
"statusmessage":"Success",
"data":
[
{
"graphtype":"headcountgraph",
"xlabel":"state",
"ylabel":"count",
"s1":"contact",
"s2":"User",
"data":
[
"Total Contacts: 1 Users: 36",
[
{
"x":"India",
"s1":"3",
"s2":"3",
"lat":"22",
"long":"77"
}
]
]
}

]
}
}
};


I need to Assign
$scope.state = India
,

How to fetch that ? I have tried giving
$scope.state = json.response.data[0].data[1][0].x
, which returns undefined data.

The thing is it has key and entry. I really lacking to fetch entry values from the code.

I gave code this way

$.each(data, function(key, entry) { x.push(parseInt(entry.x)});


but it gives me values [india] in my console.

Answer

Try giving $scope.state = response.json.response.data[0].data[1][0].x ;

Your statement doesn't start from the root response object.