Home > Web Front-end > Vue.js > How to convert string to json object in vue

How to convert string to json object in vue

WBOY
Release: 2022-03-23 11:38:32
Original
13127 people have browsed it

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);".

How to convert string to json object in vue

The operating environment of this article: Windows 10 system, Vue version 2.9.6, DELL G3 computer.

How to convert string to json object in vue

Convert Json string to json object

1. Use eval

result = eval('(' + jsonstr + ')'); // jsonstr是json字符串
Copy after login

2. Use JSON.parse ()

result = JSON.parse(jsonstr); // jsonstr是json字符串
Copy after login

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!

Related labels:
vue
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template