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

How to convert string to json object in vue

WBOY
WBOYOriginal
2022-03-23 11:38:3213061browse

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字符串

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!

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