About uncaught syntaxerror:unexpected token o in JSON at position 1,chrome Continuous error related parsing

Source: Internet
Author: User

Today to share with you the first two days I met a bug, say it is very uncomfortable, because this bug took me one hours to find the reason, and then the inexplicable failure disappeared, obsessive-compulsive disorder I, actually spent 2 hours to deliberately re-create this bug, just want to understand why??? The result everyone should have guessed, haha, did not find!!! Yes, I didn't find it!!! But similar to uncaught syntaxerror:unexpected token ' in JSON at position 2 error ...

About Josn method, everyone through Baidu should have a deep understanding of its usage: parse is used to parse a JSON object from a string; Stringify () is used to parse a string from an object;

I was doing a local storage two days ago, when I encapsulated a function through localstorage, I stored the object through Josn.stringify () locally, jump to the page, and then through the Josn.parse ()

When the JSON string is converted to an object, the bug appears!!! Some of the code is as follows:

Note: conversion to JSON string storage

Remarks: JSON string Conversion object

It took one hours to find the problem, and Chrome kept the error,uncaught syntaxerror:unexpected token o in the JSON at position 1; Open degrees Niang, directly to the problem copy sticky paste, really what kind of solution have, suddenly ...

Remember to open the first solution, is a foreign programmer a lad, said for a long while, I figured out that he meant maybe Josn.parse () the contents of the parentheses may already be an object, there is no need to convert, But I opened my localstorage clearly or string ah (the original bug map has not been found,), dead Horse when live horse medicine, I still tried a try, despair!!!

Later tried to try online another way, I believe we have seen, but some did not solve the problem!!! But the idea is right,

Remarks: Josn method for strict definition of symbols

But what we can find is that the error is position 2, not my 1; but it reminds me that JSON converting objects to strings stored locally is a strict requirement, such as symbols, or illegal strings, which can affect the parsing of the later Josn.parse ...

At this moment has suppressed oneself to stir the heart, direct localstorage.clear (); Clears the previous local storage ... Haha, sure enough problem solved, no more error ... I'm not happy. Suddenly forget the important thing, lying slot bug no record!!! So it was two hours later to find the "BUG" ...

Well, thank you so handsome, you can read my share ... Give you a flower?

About uncaught syntaxerror:unexpected token o in JSON at position 1,chrome Continuous error related parsing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.