当前位置:网站首页>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
边栏推荐
- MFC窗口滚动条用法
- LeetCode 144二叉树的前序遍历、LeetCode 114二叉树展开为链表
- 8. 字符串转换整数 (atoi)
- IPv4和IPv6、局域网和广域网、网关、公网IP和私有IP、IP地址、子网掩码、网段、网络号、主机号、网络地址、主机地址以及ip段/数字-如192.168.0.1/24是什么意思?
- Edlines: a real time line segment detector with a false detection control
- 168. excel table column name
- [ta - Frost Wolf May - 100 people plan] 2.3 Introduction aux fonctions communes
- 【EI检索】2022年第六届材料工程与先进制造技术国际会议(MEAMT 2022)重要信息会议网址:www.meamt.org会议时间:2022年9月23-25日召开地点:中国南京截稿时间:2
- 用小程序的技术优势发展产业互联网
- 【TA-霜狼_may-《百人计划》】2.1 色彩空间
猜你喜欢
Online public network security case nanny level tutorial [reaching out for Party welfare]
5、【WebGIS实战】软件操作篇——服务发布及权限管理
TEC: Knowledge Graph Embedding with Triple Context
The preorder traversal of leetcode 144 binary tree and the expansion of leetcode 114 binary tree into a linked list
二叉树神级遍历:Morris遍历
【TA-霜狼_may-《百人计划》】2.1 色彩空间
Promql select time series
Take you through a circuit board, from design to production (dry goods)
pytorch中的双线性插值上采样(Bilinear Upsampling)、F.upsample_bilinear
[deep learning] activation function (sigmoid, etc.), forward propagation, back propagation and gradient optimization; optimizer. zero_ grad(), loss. backward(), optimizer. Function and principle of st
随机推荐
Use of comment keyword in database
ASGNet论文和代码解读2
409. 最长回文串
Edge drawing: a combined real-time edge and segment detector
Promql select time series
二叉树神级遍历:Morris遍历
Take you through a circuit board, from design to production (dry goods)
72. edit distance
[shortcut key]
Research on target recognition and tracking based on 3D laser point cloud
6. zigzag transformation
The method to measure the similarity of two vectors: cosine similarity, pytorch calculate cosine similarity: torch nn. CosineSimilarity(dim=1, eps=1e-08)
【伸手党福利】开发人员重装系统顺序
Listener listener
报错:Plug-ins declaring extensions or extension points must set the singleton directive to true
242. valid Letter heteronyms
[party benefits] jsonobject to string, leave blank
在线公网安备案保姆级教程【伸手党福利】
241. Design priorities for operational expressions
[daily training] 1175 Prime permutation