parse json data in angular controller

和自甴很熟 提交于 2019-12-11 18:08:25

问题


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"
}

回答1:


[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


来源:https://stackoverflow.com/questions/20896243/parse-json-data-in-angular-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!