我正在遍历json数据...但无法在console.log中获取值
你们能告诉我如何解决吗。
我正在为控制台编写正确的语法。
在下面提供我的代码...

http://jsfiddle.net/7Bn63/4/

function allProfile() {
    for (var i = 0; i < allProfile.length; i++) {
        console.log("i am here");
        console.log(allProfile[i].Class of Service 1);
    }
}

var allProfile = [{
    Profile: 101,
        'Class of Service 1': '90%'

}];

最佳答案

您将使用方括号符号来访问该属性

allProfile[i]['Class of Service 1']


并且您的函数具有与对象相同的名称,因此已被覆盖

function iterator() {
    for (var i = 0; i < allProfile.length; i++) {
        console.log(allProfile[i]['Class of Service 1']);
    }
}

var allProfile = [{
    Profile: 101,
    'Class of Service 1': '90%'
}];

iterator();


FIDDLE

07-28 01:01