Home >Web Front-end >Vue.js >How to convert string to json object in vue
How to convert string to json object in vue: 1. Use eval, the syntax is "result = eval('('jsonstr')');"; 2. Use "JSON.parse()", The syntax is "result = JSON.parse(jsonstr);".
The operating environment of this article: Windows 10 system, Vue version 2.9.6, DELL G3 computer.
Convert Json string to json object
1. Use eval
result = eval('(' + jsonstr + ')'); // jsonstr是json字符串
2. Use JSON.parse ()
result = JSON.parse(jsonstr); // jsonstr是json字符串
The difference between eval and JSON.parse:
eval is a method supported by javascript, and data in strict json format can also be converted
JSON.parse is a conversion method supported by browsers. It must be in standard json format to convert
[Related recommendations: "vue .js tutorial》】
The above is the detailed content of How to convert string to json object in vue. For more information, please follow other related articles on the PHP Chinese website!