Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> JavaScript

Hàm JSON.stringify() trong JavaScript

Hàm JSON.stringify() chuyển đổi một giá trị JavaScript thành chuỗi JSON. Có thể tùy chọn hàm replacer hoặc mảng replacer để lọc/transform các thuộc tính.

Cú pháp

Cú pháp của nó như sau:

JSON.stringify(value[, replacer[, space]])

Ví dụ

<html> <head>    <title>Ví dụ JavaScript</title> </head> <body>    <script type="text/javascript">       var jsonSample = '{Tutorial: Java, Version:8}';       jsonObj = JSON.stringify(jsonSample);       document.write(jsonObj);    </script> </body> </html>

Kết quả

"{Tutorial: Java, Version:8}"