0

In my controller I do a http GET request to fetch a JSON array. However, before I'm able to do anything with this JSON array, Angular gives a parsing error.

JSON array:

[
  [
    "",
    "postcond",
    "Stéphanie:stap 1",
    "Actor1:stap 2",
    "Stéphanie:stap 3"
  ],
  [
    "",
    "postcond",
    "Stéphanie:stap 1",
    "Actor1:stap 2",
    "Stéphanie:stap 1"
  ]
]

http request:

$http.get(serverPrefix + "project/" + projectid + "/usecase/" + usecaseid+"/stories")
.success(function (response) {


})
.error(function (response) {$location.path('/project/'+projectid+'/usecase/'+usecaseid); });

the error:

SyntaxError: Unexpected token [
at Object.parse (native)
at pc (http://vopro5.ugent.be/stephanie/scripts/angular.min.js:14:208)
at Zb (http://vopro5.ugent.be/stephanie/scripts/angular.min.js:76:379)
at http://vopro5.ugent.be/stephanie/scripts/angular.min.js:77:237
at s (http://vopro5.ugent.be/stephanie/scripts/angular.min.js:7:302)
at Zc (http://vopro5.ugent.be/stephanie/scripts/angular.min.js:77:219)
at c (http://vopro5.ugent.be/stephanie/scripts/angular.min.js:78:349)
at http://vopro5.ugent.be/stephanie/scripts/angular.min.js:112:20
at l.$get.l.$eval (http://vopro5.ugent.be/stephanie/scripts/angular.min.js:125:305)
at l.$get.l.$digest (http://vopro5.ugent.be/stephanie/scripts/angular.min.js:122:398)

According to http://jsonlint.com/ it's a valid JSON string.

  • 2
    It's likely to be a character encoding issue, JSON needs to be in UTF-8 (maybe other Unicode flavors too, I forget). Now it may be a valid JSON string when you copy/paste it into jsonlint, but your webserver may be passing it as something else like ANSI, either because the script generating it gives that kind of output or because you saved the JSON text file as a non-UTF-8 encoding. – Fasermaler Apr 30 '15 at 10:45
0

Assign values to scope object and you get array 0 and 1 index values. Try with following code and let me...

  $scope.test = [
[
    "",
    "postcond",
    "Stéphanie:stap 1",
    "Actor1:stap 2",
    "Stéphanie:stap 3"
],
[
    "",
    "postcond",
    "Stéphanie:stap 1",
    "Actor1:stap 2",
    "Stéphanie:stap 1"
]
];

for (var key in $scope.test) {
    if ($scope.test.hasOwnProperty(key)) {
        console.log(key + "-- " + $scope.test[key]);
    }
}
| improve this answer | |
  • Are you got, what you expected. – ipln Apr 30 '15 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.