凡夫俗子_
2016-01-27 03:32
采纳率: 0%
浏览 1.6k
已采纳

新人贴,有关于循环遍历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" 循环就报错了。 求解啊! 先谢谢各位了

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

6条回答 默认 最新

  • 最佳回答

    要原始结构直接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));
    
    评论
    解决 无用
    打赏 举报
查看更多回答(5条)

相关推荐 更多相似问题