Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I get this json data by $http.get and did the assigning like this $scope.a = data.a,how to access x? when I print a in console it shows [object Object],[object Object] , shouldn't it be [object Object Object],[object Object Object] ? And when I use $scope.a[0].x[0], it says undefined. Any idea how to solve it?

{
    "a": [{
            "x":1385118661279,
            "y":{
                "y1":25,
                "y2":"12"
            },
            "z":[
                {
                    "z1":20
                },
                {
                    "z2":23
                }
            ]
        },
        {
            "x":1385118650279,
            "y":{
                "y1":25,
                "y2":"32"
            },
            "z":[
                {
                    "z1":21
                },
                {
                    "z2":22
                }
            ]
        }],

    "b": "text"
}
share|improve this question
    
well a contains an array but x doesn't, so wouldn't $scope.a[0].x be what you want? – Claies Jan 3 '14 at 3:54
    
thanks, you are right. i was having trouble with z, I thought i could do $scope.a[0].z.z1 but z is an array, so $scope.a[0].z[0].z1 worked. – Blake Jan 3 '14 at 4:01
up vote 3 down vote accepted
[object Object],[object Object]

means it is an array of objects. the brackets above does not refer to array, it simply means it is an object.

For your next question, the nested 'x' is not an array. You can access it by:

$scope.a[0].x
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.