#今天的项目用到,看俊哥找到,特此记录下来

步骤:

1、在html页面中输入下面的标签,必须是在pre标签内输出格式才会生效:

 

<pre id="songReqJson"></pre>  

 

2、js代码如下:

 

var songResJson={  
02.          "service": "ALL",  
03.          "qt": 581,  
04.          "content": {  
05.            "answer": {  
06.              "song": "如果缘只到遇见",  
07.              "album": "如果缘只到遇见",  
08.              "artist": "吴奇隆 严艺丹",  
09.              "pic_url": "http://p1.music.126.net/-u3WgIXsFNCW7d8Jy7pCEA==/5921969627395387.jpg"  
10.            },  
11.            "scene": "music"  
12.          }  
13.        }  
14.//歌曲场景  
15.$("#songResJson").text(JSON.stringify(songResJson,null,2));  

这里主要用到了JSON.stringify(songResJson,null,2)方法,

 

其中songResJson是在js中声明的json对象,2表示缩进两个空格。

其详细用法可查看:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

还可以添加样式,参见:http://www.jianshu.com/p/04127d74d88c

来源:http://blog.csdn.net/zhengxiangwen/article/details/68927330

相关文章:

  • 2021-09-30
  • 2022-12-23
  • 2021-08-24
  • 2021-12-28
  • 2021-11-29
猜你喜欢
  • 2022-01-25
  • 2021-12-28
  • 2021-12-20
  • 2022-02-05
  • 2021-09-30
相关资源
相似解决方案