Home  >  Article  >  Web Front-end  >  How to convert json to string in vue

How to convert json to string in vue

藏色散人
藏色散人Original
2021-10-26 11:07:017836browse

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.

How to convert json to string in vue

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What is app.vueNext article:What is app.vue