程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程解疑 >> 腳本-新人貼,有關於循環遍歷json格式的問題,求罩啊各位老大!

腳本-新人貼,有關於循環遍歷json格式的問題,求罩啊各位老大!

編輯:編程解疑
新人貼,有關於循環遍歷json格式的問題,求罩啊各位老大!

{"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));
u013047803
shunxiaotian
showbo
u013047803
showbo
showbo
u013047803
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved