{"curPage":"1","totalPage":"1","title":[{"id":22,"title":"《蘑菇戰爭》通關技巧防守篇","userid":3,"typeid":5,"pubtime":1461686400000,"readtimes":0,"articlePic":null,"orderNum":22},{"id":23,"title":"《蘑菇戰爭》通關技巧進攻篇","userid":2,"typeid":5,"pubtime":1456243200000,"readtimes":0,"articlePic":null,"orderNum":23},{"id":24,"title":"《蘑菇戰爭》游戲攻略 新手必看","userid":3,"typeid":5,"pubtime":1434988800000,"readtimes":0,"articlePic":null,"orderNum":24}]}
我想在js腳本裡面循環輸出這個json格式,改怎樣循環呀 我用$.each循環試了下,能單獨循環 {"title":[{"id":22,"title":"《蘑菇戰爭》通關技巧防守篇","userid":3,"typeid":5,"pubtime":1461686400000,"readtimes":0,"articlePic":null,"orderNum":22},{"id":23,"title":"《蘑菇戰爭》通關技巧進攻篇","userid":2,"typeid":5,"pubtime":1456243200000,"readtimes":0,"articlePic":null,"orderNum":23},{"id":24,"title":"《蘑菇戰爭》游戲攻略 新手必看","userid":3,"typeid":5,"pubtime":1434988800000,"readtimes":0,"articlePic":null,"orderNum":24}]} 但是加了"curPage":"1","totalPage":"1" 循環就報錯了。 求解啊! 先謝謝各位了
要原始結構直接JSON.stringify就行了,IE7-需要導入json2.js類庫,不支持json對象
var o={"curPage":"1","totalPage":"1","title":[{"id":22,"title":"《蘑菇戰爭》通關技巧防守篇","userid":3,"typeid":5,"pubtime":1461686400000,"readtimes":0,"articlePic":null,"orderNum":22},{"id":23,"title":"《蘑菇戰爭》通關技巧進攻篇","userid":2,"typeid":5,"pubtime":1456243200000,"readtimes":0,"articlePic":null,"orderNum":23},{"id":24,"title":"《蘑菇戰爭》游戲攻略 新手必看","userid":3,"typeid":5,"pubtime":1434988800000,"readtimes":0,"articlePic":null,"orderNum":24}]}
alert(JSON.stringify(o));