简体   繁体   English

尝试在简单对象上执行JSON.parse时出现“意外令牌”错误

[英]I am getting an “Unexpected token” error when trying to do JSON.parse on a simple object

I have the following code: 我有以下代码:

var a = localStorageService.get('selectedQuestionSortOrder');
$scope.selectedQuestionOrderBy = JSON.parse(a);
var b = 99;

When I look with the debugger I see: 当我看着调试器时,我看到:

a
-
Object
key: "questionStatusId"
label: "status"

After I execute the second line I get the message: 执行第二行后,我收到消息:

SyntaxError: Unexpected token o
    at Object.parse (native)
    at new <anonymous> (http://127.0.0.1:81/Content/app/admin/controllers/question-controller.js:71:47)
    at d (http://127.0.0.1:81/Scripts/angular-v1.1.5.min.js:28:304)
    at Object.instantiate (http://127.0.0.1:81/Scripts/angular-v1.1.5.min.js:28:434)
    at $get (http://127.0.0.1:81/Scripts/angular-v1.1.5.min.js:53:326)
    at http://127.0.0.1:81/Scripts/angular-v1.1.5.min.js:44:274
    at n (http://127.0.0.1:81/Scripts/angular-v1.1.5.min.js:7:74)
    at k (http://127.0.0.1:81/Scripts/angular-v1.1.5.min.js:44:139)
    at e (http://127.0.0.1:81/Scripts/angular-v1.1.5.min.js:40:139)
    at http://127.0.0.1:81/Scripts/angular-v1.1.5.min.js:39:205 

Can someone give me some advice as to what might be going wrong? 有人可以给我一些有关可能出问题的建议吗?

No need of JSON.parse(a); 不需要JSON.parse(a); since a is already an Object. 因为a已经是一个对象。

暂无
暂无

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

相关问题 尝试解析简单的json对象时,为什么JSON.parse()抛出Uncaught SyntaxError:Unexpected token? - Why does JSON.parse() throw Uncaught SyntaxError: Unexpected token when trying to parse a simple json object? 我正在使用Ionic并收到错误消息:SyntaxError:JSON中的意外标记&lt;在JSON.parse位置0处( <anonymous> ) - I am using ionic and getting an error: SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse (<anonymous>) 使用JSON.parse时,出现“ SyntaxError:JSON中位置1的意外令牌” - I am getting “SyntaxError: Unexpected token ' in JSON at position 1” when using JSON.parse 从asyncStorage获取时的JSON.parse(object)引发错误:位置1的JSON中的意外令牌o - JSON.parse(object) when getting from asyncStorage throws error: Unexpected token o in JSON at position 1 使用JSON.parse将字符串(变量)转换为对象,错误意外令牌 - Convert a string (variable ) to object with JSON.parse , error unexpected token 我在 JSON.parse 的位置 0 处不断收到 JSON 中的错误意外令牌 b? - I keep getting the error unexpected token b in JSON at position 0 at JSON.parse? 在 REST 响应上使用 JSON.parse(...) 时出现 Unexpected Token U 错误 - getting Unexpected Token U error when using JSON.parse(…) on REST Response json.parse意外令牌错误 - json.parse unexpected token error JSON.parse提供了意外的令牌错误 - JSON.parse gives unexpected token error 获取 JSON.parse 意外字符错误 - Getting JSON.parse unexpected character error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM