VibinReji Y VibinReji Y - 2 months ago 9
AngularJS Question

Integer json Object json in angularjs

I have json result which contain set of json objects.I could not get json object because json object is in integer value.Here is my json result

{
"hotnumber": {
"1": {
"Rank": 1,
"Total": "11",
"Number": "39",
"First": "4",
"Second": "4",
"Third": "3"
},
"2": {
"Rank": 2,
"Total": "10",
"Number": "25",
"First": "2",
"Second": "4",
"Third": "4"
},
"3": {
"Rank": 3,
"Total": "10",
"Number": "34",
"First": "3",
"Second": "3",
"Third": "4"
},
"4": {
"Rank": 4,
"Total": "9",
"Number": "65",
"First": "2",
"Second": "5",
"Third": "2"
},
"5": {
"Rank": 5,
"Total": "9",
"Number": "84",
"First": "4",
"Second": "3",
"Third": "2"
}
}
}


Here is the code what i tried

$http({
url : baseUrl,
method :'Post',
data : param
})
.success(function (result) {
$scope.rank =result.hotnumber.1.Rank;

}


Is there anyway to get json objects? help me. Thanks in advance

Answer

for string as a key ("1" is a string), use brackets notation:

$http({
                    url : baseUrl,
                    method :'Post',
                    data : param
                }) 
                .success(function (result) {  
        $scope.rank = result.hotnumber["1"].Rank;  

}

notice hotnumber["1"] instead of hotnumber.1