0
var jsonURL='../../json/xx.json'

var myApp = angular.module('myApp',[]);

myApp.controller('loaddata_traceroute', ['$scope','$http',function($scope, $http){

  $http.get(jsonURL).success(function(data) {
    $scope.datapoints_traceroute = data[0].abc[0].base-uri;
  })
}]);

I am trying to parse json through the code above. It works fine. However, if I try to parse deeper by adding ".base-uri", I can no longer parse it. I suspect that it is due to a reserved keyword because the error thrown in the console of Chrome is, "ReferenceError: uri is not defined"

Is there any other way to mitigate this?

2 Answers 2

2

Use square brackets:

data[0].abc[0]['base-uri'];

This is a way to refer to properties that don't conform.

Sign up to request clarification or add additional context in comments.

Comments

-1

Try..

$http.get(jsonURL).success(function(data) {
    $scope.datapoints_traceroute = data[0].abc[0]['base-uri'];
});

You can't access hyphenated parameter names directly without using square brackets and quoting the name.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.