Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the method of transferring json to string by vue?

Shulou Source: shulou.com Published: 2022-06-02 23:48:46 09月11日 Update

This article introduces the relevant knowledge of "what is the method of vue converting json to string". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Vue will json to string method: 1, open the corresponding js code; 2, through the "arr.join (',');" method to concatenate the array items into strings.

This article operating environment: Windows7 system, Vue2.9.6, Dell G3 computer.

How does vue convert json to string?

Vue string to Json conversion:

one。 Conversion between string and array

1. Convert a string to an array

Str.split (','); / / A split string with a comma

2. Convert an array to a string

Arr.join (','); / / concatenate array items into strings, separated by commas

II. Convert Json string to json object

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 introduction of "what is the method for vue to transfer json to string". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Characters strings arrays methods contents methods more formatting knowledge commas support utility learning and then in between code dilemmas reality objects situations Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology macOS Linux Apple Shulou Information