【发布时间】:2019-01-28 23:23:44
【问题描述】:
如下所示,我将一个带有逗号分隔值的字符串从弹簧控制器返回到角度控制器。
app.controller('myListController', ['$scope', function ($scope) {
//get data dynamically , logic..
$scope.myList = response;
console.log("$scope.myList " + $scope.myList); // "one,two","three","four","five,eight,nine"
//here i want to print as one,two,three,four,five,eight,nine
//convert string to array with comma separated values
var array_list = JSON.parse($scope.myList);
console.log("array_list :: " + array_list);
}]);
以上代码报错
angular.min.js?dummy=0.6014859345541128:119 SyntaxError: Unexpected token , in JSON at position 15
at JSON.parse (<anonymous>)
相同的代码,当替换为静态代码时,它按预期工作。 示例:
$scope.myList = ["one,two","three","four","five,eight,nine"];
console.log("$scope.myList static content:: " + $scope.myList); //one,two,three,four,five,eight,nine
以上有什么意见吗?
【问题讨论】:
标签: javascript angularjs html-parsing