我得到了一个“;意外的令牌“;尝试对简单对象执行JSON.parse时出错

I am getting an "Unexpected token" error when trying to do JSON.parse on a simple object

本文关键字:简单 单对象 出错 parse JSON 执行 令牌 意外 一个      更新时间:2023-09-26

我有以下代码:

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

当我用调试器查看时,我看到:

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

在我执行第二行之后,我得到消息:

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 

有人能给我一些可能出问题的建议吗?

不需要JSON.parse(a);,因为a已经是Object了。