我刚接触AngularJS时,我想了解控制台中显示的错误消息。您可以在下面找到我的json对象和其他详细信息。
在JSP页面中:
<body id="bodyID" ng-controller="ApplicationParameterController" >
<div ng-cloak class="ng-cloak">{{init(${displayInfo})}}</div>
<toaster-container toaster-options="{'time-out': 3000}"></toaster-container>
<application-param></application-param>
</body>
我的json对象:
displayInfo = [{"id":34,"key":"a","value":"true","description":"a","privilege":{"privilegeID":77,"privilegeCode":"app_param_admin"}},{"id":35,"key":"summaryReportEmail","value":"test@gmail.com","description":"summaryReportEmail","privilege":{"privilegeID":77,"privilegeCode":"app_param_admin"}},{"id":36,"key":"b","value":"true","description":"b","privilege":{"privilegeID":77,"privilegeCode":"app_param_admin"}},{"id":1,"key":"T_AND_C_ON","value":"Y","description":"c","privilege":{"privilegeID":74,"privilegeCode":"enable_tnc"}},{"id":3,"key":"soapAddress","value":"http://test.com/test/test.asmx","description":"soapAddress","privilege":{"privilegeID":77,"privilegeCode":"app_param_admin"}},{"id":4,"key":"soapAddressAlter","value":"http://test.com/test/test.asmx","description":"soapAddressAlter","privilege":{"privilegeID":77,"privilegeCode":"app_param_admin"}},{"id":27,"key":"d","value":"d","description":"d ","privilege":{"privilegeID":77,"privilegeCode":"app_param_admin"}},{"id":28,"key":"sts.s3.bucket.name","value":"test01-sts-healix-xmls","description":"sts.s3.bucket.name","privilege":{"privilegeID":77,"privilegeCode":"app_param_admin"}},{"id":29,"key":"e","value":"e","description":"e","privilege":{"privilegeID":77,"privilegeCode":"app_param_admin"}},{"id":30,"key":"f","value":"f/g","description":"f","privilege":{"privilegeID":77,"privilegeCode":"app_param_admin"}},{"id":31,"key":"g","value":"7","description":"g","privilege":{"privilegeID":77,"privilegeCode":"app_param_admin"}},{"id":32,"key":"enableScheduler","value":"true","description":"enableScheduler","privilege":{"privilegeID":77,"privilegeCode":"app_param_admin"}},{"id":33,"key":"sts.document.api","value":"http://www.test.com/as-da-api","description":"sts.document.api","privilege":{"privilegeID":77,"privilegeCode":"app_param_admin"}}]
我收到以下错误:
Error: [$parse:syntax] http://errors.angularjs.org/1.3.0-beta.14/$parse/syntax?p0=undefined&p1=is%20unexpected%2C%20expecting%20%5B%7D%5D&p2=null&p3=init(%5B%7B%22id%22%3A34%2C%22key%22%3A%22isAutoRenewalEnable%22%2C%22value%22%3A%22true%22%2C%22description%22%3A%22isAutoRenewalEnable%22%2C%22privilege%22%3A%7B%22privilegeID%22%3A77%2C%22privilegeCode%22%3A%22app_param_admin%22&p4=init(%5B%7B%22id%22%3A34%2C%22key%22%3A%22isAutoRenewalEnable%22%2C%22value%22%3A%22true%22%2C%22description%22%3A%22isAutoRenewalEnable%22%2C%22privilege%22%3A%7B%22privilegeID%22%3A77%2C%22privilegeCode%22%3A%22app_param_admin%22 G/<@https://localhost:8443/travelinsurance-aggregator/resources/scripts/angular.min.js:6:457
我的初始化方法是:
$scope.init = function(displayInfo) {
if ($scope.displayInformation == null || $scope.displayInformation == 'undefined') {
$scope.displayInformation = angular.fromJson(displayInfo);
$scope.applicationParameters = $scope.displayInformation;
}
};
当我尝试json formatter时,它显示没有语法错误,但在错误消息中显示存在语法错误。我经历了一些网站,但我找不到错误解决方案。
任何人都可以帮忙解决问题吗?提前谢谢。
答案 0 :(得分:0)
我发现了这个问题。当我尝试将对象的对象转换为json字符串时,我使用下面的代码:
ObjectMapper jsonMapper = new ObjectMapper();
String displayJson = null;
try {
displayJson = jsonMapper.writeValueAsString(applicationParametersForPrivilege);
} catch (Exception e) {
e.printStackTrace();
}
但是从this link我改为:
ObjectWriter jsonMapper = new ObjectMapper().writer().withDefaultPrettyPrinter();
String displayJson = null;
try {
displayJson = jsonMapper.writeValueAsString(applicationParametersForPrivilege);
} catch (Exception e) {
e.printStackTrace();
}
现在工作正常。