簡體   English   中英

嘗試在簡單對象上執行JSON.parse時出現“意外令牌”錯誤

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

我有以下代碼:

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已經是一個對象。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM