背景:

主要是为了方便观看。


步骤:

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

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



2、js代码如下:

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

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

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