JSON.stringify()
Translation results:
JSON is usually used to exchange data with the server.
JSON.stringify()syntax
When sending data to the server, it is usually a string.
We can use the JSON.stringify() method to convert JavaScript objects into strings.
JSON.stringify()example
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php.cn</title> </head> <body> <h2>将 JavaScript 对象转换Wie JSON 字符串</h2> <p id="demo"></p> <script> var obj = { "name":"php.cn", "alexa":10000, "site":"www.php.cn"}; var myJSON = JSON.stringify(obj); document.getElementById("demo").innerHTML = myJSON; </script> </body> </html>
Run instance »
Click the "Run instance" button to view the online instance