Am newbie to Json am getting this error while call json my json file expected ',' or ']'
[
{
"modules":
[
{
"title":"name of module1",
"description":"description of module1",
"weeks":[{"id":1, "title":"Week 01"}]
},
{
"title":"name of module2",
"description":"description of module2",
"weeks":[{"id":2, "title":"Week 02"},{"id":3,"title":"Week 03"}]
}
]
},
{
"products":
[
{
"url":"http://dummyimage.com/242x200/f3f3f3/2d2d2d.png",
"description":"Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.",
"viewurl" : "/",
"savebtn" : "save"
},
{
"url":"http://dummyimage.com/242x200/f3f3f3/2d2d2d.png",
"description":"Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.",
"viewurl" : "/",
"savebtn" : "save"
}
]
}
]
hope i did correct i dont know what is happening its getting Error: JSON.parse: expected ',' or ']' after array element am attempting to use in angular js controller
app.controller('settingsController', function($scope, $http){
$http.get('assets/javascripts/datas.json').then(function(result){
$scope.employe = result.data;
$scope.prod = result
})
});
and in view
<div class="col-sm-6 col-md-4" ng-repeat="datas in prod.products">
<div class="thumbnail">
<img ng-src="{{ datas.url }}" alt="product">
<div class="caption">
<h3>{{ datas.caption}} </h3>
<p>{{ datas.description}}</p>
<p><a role="button" class="btn btn-primary" ng-href="{{datas.viewurl}}">Button</a> <a role="button" class="btn btn-default" href="#">{{datas.savebtn}}</a></p>
</div>
</div>
</div>
and the error in console
Error: JSON.parse: expected ',' or ']' after array element at line 76 column 9 of the JSON data cc@/test/assets/javascripts/vendors/angular.js:14:289 Ud/this.defaults.transformResponse<@/test/assets/javascripts/vendors/angular.js:69:58 xc/<@/test/assets/javascripts/vendors/angular.js:68:352 r@/test/assets/javascripts/vendors/angular.js:7:288 xc@/test/assets/javascripts/vendors/angular.js:68:336 b@/test/assets/javascripts/vendors/angular.js:70:65 ye/e/l.promise.then/K@/test/assets/javascripts/vendors/angular.js:100:59 ye/f/<.then/<@/test/assets/javascripts/vendors/angular.js:101:235 Zd/this.$get
This error occurred for me when I parsed JSON from a string literal. When I copied in the JSON, I forgot that the escape sequences would need to be double escaped.
Example of the problem:
var data = JSON.parse('[{"key": "This value has \"a quoted\" string"}]');
While the string value is valid JSON, the escape sequences are lost. Then need to be double escaped:
Corrected version:
var data = JSON.parse('[{"key": "This value has \\\"a quoted\\\" string"}]');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With