当前位置:网站首页>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
边栏推荐
- 【EI会议】2022年国际土木与海洋工程联合会议(JCCME 2022)
- Edge drawing: a combined real-time edge and segment detector
- Explain spark operation mode in detail (local+standalone+yarn)
- Complete knapsack problem
- 4. [WebGIS practice] software operation chapter - data import and processing
- [ta - Frost Wolf May - 100 people plan] 2.3 Introduction aux fonctions communes
- 5、【WebGIS实战】软件操作篇——服务发布及权限管理
- [nine day training] content III of the problem solution of leetcode question brushing Report
- The method to measure the similarity of two vectors: cosine similarity, pytorch calculate cosine similarity: torch nn. CosineSimilarity(dim=1, eps=1e-08)
- 171. Excel 表列序号
猜你喜欢

FCN full Convolution Network Understanding and Code Implementation (from pytorch Official Implementation)

【TA-霜狼_may-《百人计划》】1.2.3 MVP矩阵运算

bootsrap中的栅格系统

Implement pow (x, n) function

TEC: Knowledge Graph Embedding with Triple Context

Test function in pychram

jeecgboot输出日志,@Slf4j的使用方法

pytorch nn.AdaptiveAvgPool2d(1)

Appium自动化测试基础--补充:C/S架构和B/S架构说明

Binary tree god level traversal: Morris traversal
随机推荐
报错:Plug-ins declaring extensions or extension points must set the singleton directive to true
Random seed torch in deep learning manual_ seed(number)、torch. cuda. manual_ seed(number)
Are you still wasting brain cells for self-study? This interview note is definitely the ceiling of station C
187. 重复的DNA序列
Develop industrial Internet with the technical advantages of small programs
Error: plug ins declaring extensions or extension points must set the singleton directive to true
The combination of applet container technology and IOT
409. longest palindrome
Bilinear upsampling and f.upsample in pytorch_ bilinear
pytorch中的双线性插值上采样(Bilinear Upsampling)、F.upsample_bilinear
242. 有效的字母异位词
【伸手党福利】JSONObject转String保留空字段
Binary tree god level traversal: Morris traversal
Explain spark operation mode in detail (local+standalone+yarn)
LeetCode 31下一个排列、LeetCode 64最小路径和、LeetCode 62不同路径、LeetCode 78子集、LeetCode 33搜索旋转排序数组(修改二分法)
Sort linked list (merge sort)
Pytorch training deep learning network settings CUDA specified GPU visible
【TA-霜狼_may-《百人计划》】2.2 模型与材质空间
Test function in pychram
【EI检索】2022年第六届材料工程与先进制造技术国际会议(MEAMT 2022)重要信息会议网址:www.meamt.org会议时间:2022年9月23-25日召开地点:中国南京截稿时间:2