I've an encoded stringifyed JSON object stored in database, I decoded it and loaded it and tried to parse it into an object But I get
Uncaught SyntaxError: Unexpected token ' in JSON at position 2 at JSON.parse ()
Code:
var attr = new Object();
attr = JSON.parse(code[1].replace(/"/g, "'"));
Object decoded:
[{'inputs':0,'type':'variable'},{'inputD':0,'type':'variable'},{'inputI':0,'type':'variable'},{'paras':0,'type':'variable'},{'headers':0,'type':'variable'},{'menus':0,'type':'variable'},{'lists':0,'type':'variable'},{'divs':0,'type':'variable'},{'links':0,'type':'variable'},{'images':0,'type':'variable'},{'elemName':'{}','type':'object'},{'borders':[],'type':'array'},{'nested':[],'type':'array'},{'ribbons':[],'type':'array'},{'tooltips':[],'type':'array'},{'gradColors':'{}','type':'object'},{'events':'{}','type':'object'},{'sTarget':'{}','type':'object'},{'sMain':'{}','type':'object'},{'orignalStyle':'{}','type':'object'},{'objNewStyle':'{}','type':'object'},{'functions':'{}','type':'object'},{'reverse':'{}','type':'object'},{'reverseFunction':'{}','type':'object'},{'scDetails':'{}','type':'object'}]
I have same error, @Philipp Zitzmann is correct. You must valid json string at https://jsonformatter.curiousconcept.com/
valid json string must have double quote.
JSON.parse({"u1":1000,"u2":1100}) // will be ok
no quote cause error
JSON.parse({u1:1000,u2:1100})
// error Uncaught SyntaxError: Unexpected token u in JSON at position 2
single quote cause error
JSON.parse({'u1':1000,'u2':1100})
// error Uncaught SyntaxError: Unexpected token u in JSON at position 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With