Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS: Unable to parse a list of JSON

The following is the JSON I'm trying to parse:

{[{"name":"Technology"},{"name":"Engineering"},{"name":"Business"}]}

I'm getting the error below:

Unexpected token [ in JSON at position 1
    at JSON.parse (<anonymous>)
    at fromJson

I'm getting the data from a service and saving it into the controller scope using the following:

vm = this;
vm.sectorList = response.data;

And my HTML:

<div ng-repeat="sector in ctrl.sectorList">
    {{sector.name}}
</div>
like image 993
kulsoompatel Avatar asked Jan 31 '17 15:01

kulsoompatel


1 Answers

The JSON is invalid, hence the error you're getting. You're missing a key to go with the JSON array value. This for instance (key "anything" added) will work:

{"anything": [{"name":"Technology"},{"name":"Engineering"},{"name":"Business"}]}
like image 154
Hanne Olsen Avatar answered Sep 30 '22 16:09

Hanne Olsen