What Angular $ http.get syntax expects JSON?

My JSON:

[
    {"animal":"dog", "isCute":"true"},
    {"animal":"worm", "isCute":"false"},
]

When I call $ http.get () with a URL that serves this JSON, I get the following error. Is my JSON incorrect or am I doing something else wrong?

SyntaxError: Unexpected token ]
  at Object.parse (native)
  at Ib (angular.min.js:13:504)
  at e.defaults.transformResponse (angular.min.js:59:501)
  at angular.min.js:59:262
  at Array.forEach (native)
  at q (angular.min.js:7:264)
  at ac (angular.min.js:59:244)
  at c (angular.min.js:60:458)
  at r (angular.min.js:96:280)
  at angular.min.js:97:417
+4
source share
1 answer

If you have a comma after your second object, delete this:

[
    {"animal":"dog", "isCute":"true"},
    {"animal":"worm", "isCute":"false"}
]

I found JSONLint to help diagnose JSON problems like yours.

+4
source

Source: https://habr.com/ru/post/1538659/


All Articles