![](/img/trans.png)
[英]JSON syntax error: 'unexpected number' or 'JSON.parse: expected ',' or '}' after property value in object'
[英]JSON parse error on object property value
我是 JSON 的新手,我認為 JSON.parse 獲取您想要查找的鍵的值,或者至少是我從它的定義中理解的值。 但是我收到一個我無法理解的錯誤。
未處理的承諾拒絕:JSON 輸入意外結束; 區域:角度; 任務: Promise.then ; 值:SyntaxError:JSON 輸入意外結束
我的最終結果是使用atob
為每個結果轉換鍵的值。 我的代碼如下
loadUserInfo() {
this.getUsers()
.then((result) => {
for (const dx of result){
const signs = dx.signature;
console.log(JSON.parse(signs));
}
// const conv = atob(decode64);
// const myImg = `data:image/jpeg;base64,${conv}`;
//console.log(myImg);
};
}
如果我不使用 JSON.parse,我的代碼會返回正確轉換的atob
但以對象表示法
JSON 是對象表示法,用於序列化數據。
JSON.parse
是解析有效 JSON 字符串並輸出 JavaScript 對象的函數。 有相反的函數 - JSON.stringify
- 將 JavaScript 對象序列化為有效的 JSON 字符串。
loadUserInfo() {
this.getUsers()
.then((result) => {
for (const dx of result){
const signs = dx.signature;
console.log(signs); //Show this
console.log(JSON.parse(signs));
}
}).catch((reason) => {
console.log(reason); //show this too
});
}
}
如果你給這些東西,那么我們就能看到哪里出了問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.