简体   繁体   English

Angular 不删除 json 前缀

[英]Angular not removing json prefix

I have an HTTP request that looks like this in angular js我有一个在 angular js 中看起来像这样的 HTTP 请求

$http.get('appTop/appTop.json').then(function successCallback(response) {
    top.list=angular.fromJson(response.data);
}, function errorCallback(response) {
    console.log(response);
});

top.list is defined elsewhere and the file being requested does exist but every time i run the request it returns top.list 是在别​​处定义的,被请求的文件确实存在,但每次我运行请求时它都会返回

SyntaxError: Unexpected token )                    angular.js 12520

What is causing this error?是什么导致了这个错误? Since it's coming from within angular.js, I can't figure out what is wrong.由于它来自 angular.js,我无法弄清楚出了什么问题。

Just in case it is relevant, my scripts load in this order:以防万一,我的脚本按以下顺序加载:

  • jquery查询
  • jquery mobile移动版
  • angular.js angular.js
  • angular-touch.js angular-touch.js

I have not altered the angular.js file in any way, and I am loading it using the angular.min.js file.我没有以任何方式更改 angular.js 文件,我正在使用 angular.min.js 文件加载它。

For a server, I'm using a locally hosted Node.js server.对于服务器,我使用的是本地托管的 Node.js 服务器。

It has come to my attention that it may be in part because of my JSON file, so here is it:我注意到这可能部分是因为我的 JSON 文件,所以这里是:

)]}',
[{
    "page": "/main/main.html",
    "title": "Home"
}, {
    "page": "/server/server.html",
    "title": "Server"
}]

the starting )]}' , is recommended by angular for security reasons开始)]}'出于安全原因angular推荐

Update更新

The error seems to be because angular is not removing the recommended prefix.错误似乎是因为 angular 没有删除推荐的前缀。 Can anyone see why?谁能看出为什么? I updated the code snippets according to the Input I got already and it's still not parsing it correctly.我根据我已经得到的输入更新了代码片段,但它仍然没有正确解析它。

You may need to deserialize the Json that you are receiving.您可能需要反序列化您收到的 Json。

$http.get('appTop/appTop.json')
    .then(function successCallback(response) {
        top.list = angular.fromJson(response.data);
    }, function errorCallback(response) {
        console.log(response);
    });

The response.data part may just need to be response . response.data部分可能只需要response It depends on how you are receiving the response.这取决于您如何接收响应。

https://docs.angularjs.org/api/ng/function/angular.fromJson https://docs.angularjs.org/api/ng/function/angular.fromJson

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM