Uncaught SyntaxError: Unexpected token ' in JSON
how to convert this string to object in javascript?
JSON.parse( "[{'dia': '1', 'valor': '0,00'}, {'dia': '2', 'valor': '0,00'}, {'dia': '3', 'valor': '0,00'}]" );
VM85380:1 Uncaught SyntaxError: Unexpected token ' in JSON at position 0 at JSON.parse ()
JSON always needs to preceeded with single to double quotes, if you're parsing a String.
change your line to:
JSON.parse( '[{"dia": 1, "valor": "0,00"}, {"dia": 2, "valor": "0,00"}, {"dia": 3, "valor": "0,00"}]' );
PS: If you want to store your valor
as a float, you should change its format from 0,00
to 0.00
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.