值数组 json:如何使用 Angular js 获取元素?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20303366/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 20:05:54  来源:igfitidea点击:

Value array json: How to get elements with Angular js?

jsonangularjs

提问by Ruudje

The call on the api returns this json:

对 api 的调用返回此 json:

[
{
    "RESULT": {
        "TYPES": [
            "bigint",
            "varchar",
            "varchar",
            "varchar",
            "varchar",
            "varchar",
            "date",
            "varchar",
            "int",
            "int",
            "varchar"
        ],
        "HEADER": [
            "kvk",
            "bedrijfsnaam",
            "adres",
            "postcode",
            "plaats",
            "type",
            "anbi",
            "status",
            "kvks",
            "sub",
            "website"
        ],
        "ROWS": [
            [
                "273121520000",
                "Kinkrsoftware", <-- this is the value i want
                "Oude Trambaan 7",
                "2265CA",
                "Leidschendam",
                "Hoofdvestiging",
                null,
                null,
                "27312152",
                "0",
                null
            ]
        ]
    }
}
]

I can't change the api code.

我无法更改api代码。

I am using Angular and I can't see to get access to the values.

我正在使用 Angular,但无法访问这些值。

This is my controller:

这是我的控制器:

  .controller('MainCtrl', function($scope, $http, $log, kvkInfo) {

  kvkInfo.success(function(status, data) { 

        $scope.name = status;
    $scope.bedrijf = data;
    $scope.status = status;
      });


});

I have tried

我试过了

data.RESULT.ROW, data.RESULT.ROW[1], data.RESULT[0].ROW, data.RESULT[0].ROW[1], data.ROW[1]

data.RESULT.ROW, data.RESULT.ROW[1], data.RESULT[0].ROW, data.RESULT[0].ROW[1], data.ROW[1]

How can i get this element?

我怎样才能得到这个元素?

回答by JB Nizet

What you get starts with [, so it's an array. So you need data[0].

你得到的开始于[,所以它是一个数组。所以你需要data[0].

The first element of this array (data[0]) is an object (it starts with {) which has a RESULT attribute. So you can use data[0].RESULT.

此数组 ( data[0])的第一个元素是一个对象(以 开头{),它具有 RESULT 属性。所以你可以使用data[0].RESULT.

The value of the RESULT attribute is another object which has a ROWSattribute (Note the final S). So you can use data[0].RESULT.ROWS.

RESULT 属性的值是另一个具有ROWS属性的对象(注意最后的S)。所以你可以使用data[0].RESULT.ROWS.

The value of ROWS is an array, containing another array, so you need data[0].RESULT.ROWS[0][1].

ROWS 的值是一个数组,包含另一个数组,因此需要data[0].RESULT.ROWS[0][1].

回答by peaceman

Your api result is wrapped in an array, so you have to save the first element of it to the scope instead of the whole array.

您的 api 结果包含在一个数组中,因此您必须将它的第一个元素保存到范围而不是整个数组。