你好我得到使用angularjs通过Chrome控制台这个错误:
语法错误:意外的令牌ñ 在Object.parse(原生) 在fromJson(HTTP://本地主机:3000 /资产/ angular.js体= 1:803:14) 在$ HttpProvider.defaults.defaults.transformResponseHTTP://本地主机:3000 /资产/ angular.js体= 1:9471:18) 在http://本地主机:3000 /资产/ angular.js体= 1:9446:12 在Array.forEach(原生) 在的forEach(HTTP://本地主机:3000 /资产/ angular.js体= 1:149:11) 在transformData(HTTP://本地主机:3000 /资产/ angular.js体= 1:9445:3) 在transformResponse(HTTP://本地主机:3000 /资产/ angular.js体= 1:10061:17) 在wrappedCallback(HTTP://本地主机:3000 /资产/ angular.js体= 1:7510:59) 在http://本地主机:3000 /资产/ angular.js体= 1:7583:26 angular.js体= 1:6350(匿名函数)angular.js体= 1:6350(匿名函数)angular.js体= 1:5421?wrappedCallback angular.js体= 1:7512(匿名函数)angular.js体= 1:7583?范围$的eval angular.js体= 1:8927?范围$消化angular.js体= 1:8790?范围$申请angular.js体= 1:9013?DONE angular.js体= 1:10266?completeRequest angular.js体= 1:10450xhr.onreadystatechange
我做的通过角一个get()请求,其中JSON是:
[{\"_id\":\"51f96144c885552bda000015\",\"company_id\":\"51f82116c88555bf48000004\",\"description\":\"ENGINEER为了获得最佳的公司,\"industry_id\":null,\"location_city\":\"Pittsburgh\",\"location_coordinates\":[-79.9556424,40.4379259],\"location_state\":\"PA\",\"location_zip\":\"15213\",\"name\":\"Engineer },{_id:51f972a5c885552bda000026,COMPANY_ID:51f82116c88555bf48000004,说明:必须做everything\",\"industry_id\":null,\"location_city\":\"Pittsburgh\",\"location_coordinates\":[-79.9418166,40.4443735],\"location_state\":\"PA\",\"location_zip\":\"15289\",\"name\":\"job #2}]有谁知道这是什么意思?
解决方案 语法错误:意外标记ñ
往往是意外返回楠结果
在你的JSON。 NaN的
不是JSON支持的价值(尽管它会被罚款,如果它被包裹在引号的字符串),也不是不裹引号任何其他文本,除了真正
,假
和空
。所以,虽然你确实你的JSON样本中有两个空
S,它不应该成为问题。此外,在错误的'N'不是小写的,因为它会在空
。
这是大写字母N在错误的presence使我怀疑,你是不小心返回 NaN的
在某处你的JSON输出,即使它是没有present您的样本。唯一的其他资本-N你的样品中被安全地包裹在报价,并在任何情况下,字符串的中间。我把钱已经成为一个 NaN的
,特别是如果你没有消毒code $ P $从返回pventing他们,而代以零或东西。
Hi I am getting this error using angularjs through the chrome console:
SyntaxError: Unexpected token N
at Object.parse (native)
at fromJson (http://localhost:3000/assets/angular.js?body=1:803:14)
at $HttpProvider.defaults.defaults.transformResponse
http://localhost:3000/assets/angular.js?body=1:9471:18)
at http://localhost:3000/assets/angular.js?body=1:9446:12
at Array.forEach (native)
at forEach (http://localhost:3000/assets/angular.js?body=1:149:11)
at transformData (http://localhost:3000/assets/angular.js?body=1:9445:3)
at transformResponse (http://localhost:3000/assets/angular.js?body=1:10061:17)
at wrappedCallback (http://localhost:3000/assets/angular.js?body=1:7510:59)
at http://localhost:3000/assets/angular.js?body=1:7583:26 angular.js?body=1:6350
(anonymous function) angular.js?body=1:6350
(anonymous function) angular.js?body=1:5421
wrappedCallback angular.js?body=1:7512
(anonymous function) angular.js?body=1:7583
Scope.$eval angular.js?body=1:8927
Scope.$digest angular.js?body=1:8790
Scope.$apply angular.js?body=1:9013
done angular.js?body=1:10266
completeRequest angular.js?body=1:10450
xhr.onreadystatechange
I am doing a get() request through angular where the json is:
[{"_id":"51f96144c885552bda000015","company_id":"51f82116c88555bf48000004","description":"ENGINEER FOR BEST COMPANY",
"industry_id":null,"location_city":"Pittsburgh","location_coordinates":[-79.9556424,40.4379259],"location_state":"PA","location_zip":"15213","name":"Engineer "},
{"_id":"51f972a5c885552bda000026","company_id":"51f82116c88555bf48000004","description":"has to do everything","industry_id":null,"location_city":"Pittsburgh","location_coordinates":[-79.9418166,40.4443735],"location_state":"PA","location_zip":"15289","name":"job #2"}]
Does anyone know what this means?
解决方案SyntaxError: Unexpected token N
is often the result of accidentally returning a NaN
in your JSON. NaN
is not a supported value in JSON (although it would be fine if it were a string wrapped in quotes), nor is any other text that isn't wrapped in quotes, except true
, false
and null
. So, although you do indeed have two null
s in your JSON sample, it shouldn't be the problem. Further, your 'N' in the error isn't lowercase, as it would be in null
.
The presence of that capital letter 'N' in the error makes me suspect that you were accidentally returning a NaN
somewhere in your JSON output, even though it's not present in your sample. The only other capital-N's you have in your sample are safely wrapped in quotes, and are in the middle of the string in any case. I'd put money on it having been a NaN
, especially if you didn't have sanitization code preventing them from being returned, and substituting a zero or something.