I would like to know how to execute this code without errors.
var test = 'Something';
JSON.parse('{"xxx": test}');
The reason i'm asking this i have a JSON object with variables i want to use inside a data attribute. I would like to parse the JSON into an object. When have this i can use eval() to run it with the variables.
You can't.
JSON doesn't support variables.
It is a data format based on JS syntax. It is not a complete copy of the JS programming language.
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.