How to convert string into json object in vue
This article mainly introduces the relevant knowledge of how to convert string into json objects in vue, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value, I believe you will have something to gain after reading this article on how to convert string into json objects in vue. Let's take a look.
The method of converting string into json object in vue: 1, using eval, the syntax is "result = eval ('('jsonstr')');"; 2, using "JSON.parse ()", the syntax is "result = JSON.parse (jsonstr);".
This article operating environment: windows10 system, Vue2.9.6 version, DELL G3 computer.
How to convert string into json object in vue
Convert Json strings to json objects
1. Use eval
Result = eval ('('+ jsonstr +')'); / / jsonstr is the json string
2. Use JSON.parse ()
Result = JSON.parse (jsonstr); / / jsonstr is a json string
The difference between eval and JSON.parse:
Eval is supported by javascript, and data can be converted without strict json format.
JSON.parse is a conversion method supported by browsers. You must have a standard json format to convert it.
This is the end of the article on "how to convert string into json objects in vue". Thank you for reading! I believe you all have a certain understanding of "how to convert string into json objects in vue". If you want to learn more, you are welcome to follow the industry information channel.