当前位置:网站首页>Unexpected token o in JSON at position 1, JSON parsing problem
Unexpected token o in JSON at position 1, JSON parsing problem
2022-07-01 03:45:00 【My little brother】
Follow the video to log in , All of a sudden, an error was reported Unexpected token o in JSON at position 1
It seems that there should be an error in parsing , But here I use all kinds of console.log debugging , I can't find the problem
from cookie Get the user information and assign it to the object , Let's see what's given :

There should be something wrong here , There should be a problem when depositing , Wrong format 
When saving, the object is directly saved , It's not a string , hinder parse The parsing method is to parse the string into json object , So when saving , You should first convert the object to a string : cookie.set('guli_ucenter', JSON.stringify(this.loginInfo), { domain: 'localhost' })
It is very nice:
Here is JSON.parse() and JSON.stringify() usage :
JSON.parse() Used to parse... From a string json object , Such as :
var str = '{"name":"LeonWu","age":"18"}'
JSON.parse(str);
// The result is a Object
// age: "18";
// name: "LeonWu";
JSON.stringify() Used to parse a string from an object , Such as
var a = {
a:1,b:2,c:"LeonWu"};
JSON.stringify(a);
// The result is "{"a":1,"b":2,"c":"LeonWu"}"
Reasons for reporting errors : The data to be converted is originally object, This method parses a string into json object , If you convert again, you will report an error ;
Because of the Object Pass as a parameter to JSON.parse() In time , It will silently Object To string,
Will call the on the prototype first toString() Method ; The result is ”[object Object]”,JSON.parse Will be the first character ’[‘ Understood as the beginning of the array , Second character ’o’ I don't know how to deal with ; So the above error message is thrown Unexpected token o in JSON at position 1.
Reference link :
Unexpected token o in JSON at position 1 The reason for the error
边栏推荐
- Addition without addition, subtraction, multiplication and division
- Random seed torch in deep learning manual_ seed(number)、torch. cuda. manual_ seed(number)
- 【伸手党福利】开发人员重装系统顺序
- 241. 为运算表达式设计优先级
- 深度学习中的随机种子torch.manual_seed(number)、torch.cuda.manual_seed(number)
- Valentine's Day is nothing.
- 二叉树神级遍历:Morris遍历
- 166. fractions to decimals
- FCN全卷積網絡理解及代碼實現(來自pytorch官方實現)
- Split(), split(), slice(), can't you tell?
猜你喜欢

报错:Plug-ins declaring extensions or extension points must set the singleton directive to true

Unexpected token o in JSON at position 1 ,JSON解析问题
![[TA frost wolf \u may- hundred people plan] 2.4 traditional empirical lighting model](/img/05/85c004e4fbfc8d4984ac04ddb1190b.png)
[TA frost wolf \u may- hundred people plan] 2.4 traditional empirical lighting model

Ultimate dolls 2.0 | encapsulation of cloud native delivery
![[ta - Frost Wolf May - 100 people plan] 2.3 Introduction aux fonctions communes](/img/be/325f78dee744138a865c13d2c20475.png)
[ta - Frost Wolf May - 100 people plan] 2.3 Introduction aux fonctions communes
![[小样本分割]论文解读Prior Guided Feature Enrichment Network for Few-Shot Segmentation](/img/b3/887d3fb64acbf3702814d32e2e6414.png)
[小样本分割]论文解读Prior Guided Feature Enrichment Network for Few-Shot Segmentation

Edlines: a real time line segment detector with a false detection control
![Online public network security case nanny level tutorial [reaching out for Party welfare]](/img/66/d9c848a7888e547b7cb28d84aabc24.png)
Online public network security case nanny level tutorial [reaching out for Party welfare]

pytorch训练深度学习网络设置cuda指定的GPU可见

AfxMessageBox和MessageBox的用法
随机推荐
Future of NTF and trends in 2022
ASGNet论文和代码解读2
6. Z 字形变换
30. Concatenate substrings of all words
Appium automation test foundation -- supplement: c/s architecture and b/s architecture description
Promql select time series
在 C 中声明函数之前调用函数会发生什么?
【快捷键】
[ta - Frost Wolf May - 100 people plan] 2.3 Introduction aux fonctions communes
RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs
Jeecgboot output log, how to use @slf4j
10. 正则表达式匹配
衡量两个向量相似度的方法:余弦相似度、pytorch 求余弦相似度:torch.nn.CosineSimilarity(dim=1, eps=1e-08)
Addition without addition, subtraction, multiplication and division
Split(), split(), slice(), can't you tell?
Leetcode: offer 59 - I. maximum value of sliding window
Binary tree god level traversal: Morris traversal
AfxMessageBox和MessageBox的用法
[TA frost wolf \u may- hundred people plan] 2.3 introduction to common functions
242. valid Letter heteronyms