当前位置:网站首页>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
边栏推荐
- 318. Maximum word length product
- TEC: Knowledge Graph Embedding with Triple Context
- 【EI会议】2022年第三届纳米材料与纳米技术国际会议(NanoMT 2022)
- 静态库使用MFC和共享库使用MFC的区别
- 10. 正则表达式匹配
- Leetcode:829. Sum of continuous integers
- Valentine's Day is nothing.
- Random seed torch in deep learning manual_ seed(number)、torch. cuda. manual_ seed(number)
- 8. 字符串转换整数 (atoi)
- 208. 实现 Trie (前缀树)
猜你喜欢

bootsrap中的栅格系统

Cygwin的下载和安装配置

SEM of C language_ Tvariable type
![[deep learning] activation function (sigmoid, etc.), forward propagation, back propagation and gradient optimization; optimizer. zero_ grad(), loss. backward(), optimizer. Function and principle of st](/img/9f/187ca83be1b88630a6c6fbfb0620ed.png)
[deep learning] activation function (sigmoid, etc.), forward propagation, back propagation and gradient optimization; optimizer. zero_ grad(), loss. backward(), optimizer. Function and principle of st

Access denied for user ‘ODBC‘@‘localhost‘ (using password: NO)

Review column - message queue

Random seed torch in deep learning manual_ seed(number)、torch. cuda. manual_ seed(number)

TEC: Knowledge Graph Embedding with Triple Context

Bilinear upsampling and f.upsample in pytorch_ bilinear

Processing of menu buttons on the left and contents on the right of the background system page, and double scrolling appears on the background system page
随机推荐
Golang multi graph generation gif
Binary tree god level traversal: Morris traversal
Cygwin的下载和安装配置
[TA frost wolf \u may - "hundred people plan"] 2.1 color space
Gorilla/mux framework (RK boot): RPC error code design
Pyramid scene parsing network [pspnet] thesis reading
392. 判断子序列
详解Spark运行模式(local+standalone+yarn)
409. 最长回文串
Leetcode: offer 59 - I. maximum value of sliding window
Complete knapsack problem
TEC: Knowledge Graph Embedding with Triple Context
Pytorch training deep learning network settings CUDA specified GPU visible
[EI search] important information conference of the 6th International Conference on materials engineering and advanced manufacturing technology (meamt 2022) in 2022 website: www.meamt Org meeting time
静态库使用MFC和共享库使用MFC的区别
【EI会议】2022年第三届纳米材料与纳米技术国际会议(NanoMT 2022)
Bilinear upsampling and f.upsample in pytorch_ bilinear
ECMAScript 6.0
4. [WebGIS practice] software operation chapter - data import and processing
318. 最大单词长度乘积