Home > Article > Web Front-end > How to convert json to string in vue
Vue's method of converting json to string: 1. Open the corresponding js code; 2. Splice the array items into a string through the "arr.join(',');" method.
The operating environment of this article: Windows 7 system, Vue2.9.6, Dell G3 computer.
How does vue convert json to string?
Vue string and Json conversion:
1. String and array Mutual conversion
1. Convert string to array
str.split(','); // 以逗号,为拆分的字符串
2. Convert array to string
arr.join(','); // 把数组项拼接成字符串,以逗号,分隔
2. 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 , data that does not require strict json format can also be converted
JSON.parse is a conversion method supported by the browser, and the standard json format must be used to convert it
Recommendation: " The latest 5 vue.js video tutorial selections》
The above is the detailed content of How to convert json to string in vue. For more information, please follow other related articles on the PHP Chinese website!