解析在角控制器JSON数据 [英] parse json data in angular controller

查看:102
本文介绍了解析在角控制器JSON数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 $ http.get 得到这个JSON数据,做这样的分配 $ scope.a = data.a ,如何访问X - 当我打印 A 控制台就说明 [对象的对象],[对象的对象] ,应该不会是 [对象对象对象],[对象对象对象] ?当我使用 $ scope.a [0] .X [0] ,它说不确定。任何想法如何解决呢?

  {
    一个: [{
            ×:1385118661279,
            Y:{
                Y1:25,
                Y2:12
            },
            Z:[
                {
                    Z1:20
                },
                {
                    Z2:23
                }
            ]
        },
        {
            ×:1385118650279,
            Y:{
                Y1:25,
                Y2:32
            },
            Z:[
                {
                    Z1:21
                },
                {
                    Z2:22
                }
            ]
        }],    B:文本
}


解决方案

  [对象的对象],[对象的对象]

意味着它是一个对象数组。括号上述不引用数组,它只是意味着它是一个对象。

有关您的下一个问题,嵌套的'X'是不是数组。您可以通过访问:

  $ scope.a [0] .X

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

解决方案

[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

这篇关于解析在角控制器JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆