获取JSON值

时间:2018-01-12 09:00:19

标签: angularjs json

JSON

{"discountPriceValues":[[{"Price":"3.0"},{"Scode":"S0375102"}],[{"Price":"2.0"},{"Scode":"s0779548"}]],"isEmployeeOJ":"Y"}

APP.JS

var test = $http.get("data/test.json").then(function (response5) {
  $scope.testing = response5.data;
  return response5;
});
test.then(function(testing){
    $scope.testing = testing.data.discountPriceValues;
    //console.log($scope.testing);
});

如何访问isEmployeeOJ值。我尝试使用下面的代码,但我在控制台中未定义。

console.log($scope.testing.isEmployeeOJ);

3 个答案:

答案 0 :(得分:0)

需要使用angular.fromJson ||解析它JSON.parse()来

之后它只是一个JSON对象。例如:

console.log(JSON.parse($scope.testing.isEmployeeOJ));

答案 1 :(得分:-1)

this.test = {"discountPriceValues":[[{"Price":"3.0"},{"Scode":"S0375102"}],[{"Price":"2.0"},{"Scode":"s0779548"}]],"isEmployeeOJ":"Y"}

alert(this.test.isEmployeeOJ)

或在HTML中:

{{test.isEmployeeOJ}}

此代码有效:)

答案 2 :(得分:-2)

只需你可以这样做

obj = testing = {"discountPriceValues":[[{"Price":"3.0"},{"Scode":"S0375102"}],[{"Price":"2.0"},{"Scode":"s0779548"}]],"isEmployeeOJ":"Y"}
{discountPriceValues: Array(2), isEmployeeOJ: "Y"}

console.log(obj.isEmployeeOJ)