當(dāng)前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
js 语法:JSON.stringify(data, null, 4)
生活随笔
收集整理的這篇文章主要介紹了
js 语法:JSON.stringify(data, null, 4)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
JSON.stringify(data, null, 4)
JSON.stringify() 方法用于將 JavaScript 值轉(zhuǎn)換為 JSON 字符串。
JSON.stringify(data, null, 4) JSON.stringify從一個(gè)對(duì)象解析出字符串,第三個(gè)參數(shù)是格式化縮進(jìn)格式按照四個(gè)字符縮進(jìn) <!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( "只有一個(gè)參數(shù)情況:" ); document.write( "<br>" ); document.write("<pre>" + str_pretty1 + "</pre>" ); document.write( "<br>" ); str_pretty2 = JSON.stringify(str, null, 4) //使用四個(gè)空格縮進(jìn) document.write( "使用參數(shù)情況:" ); document.write( "<br>" ); document.write("<pre>" + str_pretty2 + "</pre>" ); // pre 用于格式化輸出 </script></body> </html>?
與50位技術(shù)專家面對(duì)面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的js 语法:JSON.stringify(data, null, 4)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【收藏】deepin环境安装nodejs
- 下一篇: AnotherRedisDesktopM