當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
js 语法:JSON.stringify(data, null, 4)
生活随笔
收集整理的這篇文章主要介紹了
js 语法:JSON.stringify(data, null, 4)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
JSON.stringify(data, null, 4)
JSON.stringify() 方法用于將 JavaScript 值轉換為 JSON 字符串。
JSON.stringify(data, null, 4) JSON.stringify從一個對象解析出字符串,第三個參數是格式化縮進格式按照四個字符縮進 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鳥教程(runoob.com)</title> </head> <body><p id="demo"></p> <script> var str = {"name":"菜鳥教程", "site":"http://www.runoob.com"} str_pretty1 = JSON.stringify(str) document.write( "只有一個參數情況:" ); document.write( "<br>" ); document.write("<pre>" + str_pretty1 + "</pre>" ); document.write( "<br>" ); str_pretty2 = JSON.stringify(str, null, 4) //使用四個空格縮進 document.write( "使用參數情況:" ); document.write( "<br>" ); document.write("<pre>" + str_pretty2 + "</pre>" ); // pre 用于格式化輸出 </script></body> </html>?
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的js 语法:JSON.stringify(data, null, 4)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【收藏】deepin环境安装nodejs
- 下一篇: 【收藏】SpringBlade开发手册地