jQuery   发布时间:2022-04-19  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了使用jQuery .each()解析JSON数组大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_607_4@ 我有这个jQuery函数

function getData(jsonLink){
  $(".scrollable .items").html("<img class='loadGif' src='/sites/all/themes/zen/journeyon/images/ajax-loader.gif' alt='' />");

  $.ajaxSetup({
    url: jsonLink,global: @R_696_11372@se,type: "GET"
  });

  $.ajax({
    url: jsonLink,success: function(data) {
      var output = "";
      $.each(data['nodes'],function(i,row){
        var linkType = row['node-type'];
        var lowerLinkType = linkType.toLowerCase();
        var videoLink = row["video"];
        var thumbLink = row["thumbnail"];
        var posterLink = row["poster-image"];
        var nodetitle = row["node-title"];
        var url = row['url-link'];
        if(linkType == "Episode"){
          output+='<li><a class="myRemote '+lowerLinkType+'" href="'+posterLink+'" ref="'+videoLink+'" title="Play '+nodetitle+'"><img src="'+thumbLink+'" width="123" height="67" alt="Play '+nodetitle+'" /></a></li>';
        }else if(linkType == "Slide"){
          output+='<li><a class="myRemote '+lowerLinkType+'" href="'+posterLink+'" ref="'+url+'" title="Go To '+nodetitle+'"><img src="'+thumbLink+'" width="123" height="67" alt="Go To '+nodetitle+'" /></a></li>';
        }
      });
      $(".scrollable .items").html("").append(output);
      remoteControl();
    }
  });
}

我试图解析这个数组

{
    "nodes": [
        {
            "node-title" : "Slide for Album Post","node-type" : "Slide","poster-image" : "http://journeyon.local/sites/default/files/imagecache/ticker_image/files/poster-images/Web_Graphic2.jpg","thumbnail" : "http://journeyon.local/sites/default/files/imagecache/ticker_thumbnail/files/poster-images/Web_Graphic2.jpg","video" : "","audio" : "","url-link" : "http://dev.journeystl.info/current/blogs/josh-dix/latest-worship-ep-have-thine-own-way"
        },{
            "node-title" : "Walking In The Light","node-type" : "Episode","poster-image" : "http://journeyon.local/sites/default/files/imagecache/ticker_image/files/poster-images/Sermon_2009-09-27pf.jpg","thumbnail" : "http://journeyon.local/sites/default/files/imagecache/ticker_thumbnail/files/poster-images/Sermon_2009-09-27pf.jpg","video" : "http://journeyon.local/sites/default/files/video/vodcast/Sermon_2009-09-27-Vodcast.m4v","audio" : "http://journeyon.local/sites/default/files/audio/Sermon_2009-09-27-podcast.mp3","url-link" : ""
        },{
            "node-title" : "Test Slide","poster-image" : "http://journeyon.local/sites/default/files/imagecache/ticker_image/files/poster-images/iStock_000000041926small.jpg","thumbnail" : "http://journeyon.local/sites/default/files/imagecache/ticker_thumbnail/files/poster-images/iStock_000000041926small.jpg","url-link" : "/node/3960"
        },{
            "node-title" : "Finding God at Church","poster-image" : "http://journeyon.local/sites/default/files/imagecache/ticker_image/files/poster-images/Sermon_2009-09-06pf_0.jpg","thumbnail" : "http://journeyon.local/sites/default/files/imagecache/ticker_thumbnail/files/poster-images/Sermon_2009-09-06pf_0.jpg","video" : "http://journeyon.local/sites/default/files/video/vodcast/Sermon_2009-09-05-Vodcast.m4v","audio" : "http://journeyon.local/sites/default/files/audio/Sermon_2009-09-06-podcast.mp3",{
            "node-title" : "Finding God in Brokenness","poster-image" : "http://journeyon.local/sites/default/files/imagecache/ticker_image/files/poster-images/Sermon_2009-08-30pf_0.jpg","thumbnail" : "http://journeyon.local/sites/default/files/imagecache/ticker_thumbnail/files/poster-images/Sermon_2009-08-30pf_0.jpg","video" : "http://journeyon.local/sites/default/files/video/vodcast/Sermon_2009-08-30-Vodcast.m4v","audio" : "http://journeyon.local/sites/default/files/audio/Sermon_2009-08-30-podcast.mp3",{
            "node-title" : "@R_696_11372@se Teachers","poster-image" : "http://journeyon.local/sites/default/files/imagecache/ticker_image/files/poster-images/Sermon_2009-07-26pf.jpg","thumbnail" : "http://journeyon.local/sites/default/files/imagecache/ticker_thumbnail/files/poster-images/Sermon_2009-07-26pf.jpg","video" : "http://journeyon.local/sites/default/files/video/vodcast/Sermon_2009-07-25-Vodcast.m4v","audio" : "http://journeyon.local/sites/default/files/audio/Sermon_2009-07-25_podcast.mp3",{
            "node-title" : "Confessions: A Story of Struggle,Restoration,and Hope","poster-image" : "http://journeyon.local/sites/default/files/imagecache/ticker_image/files/poster-images/PosterFrame_Confessions.jpg","thumbnail" : "http://journeyon.local/sites/default/files/imagecache/ticker_thumbnail/files/poster-images/PosterFrame_Confessions.jpg","video" : "http://journeyon.local/sites/default/files/video/vodcast/Sermon_2009-06-28-Vodcast.m4v","audio" : "http://journeyon.local/sites/default/files/audio/Sermon_2009-06-28-podcast.mp3","url-link" : ""
        } 
    ] 
}

问题是我在jQuery.js文件本身上遇到错误.

G is undefined
http://journeyon.local/sites/all/themes/zen/journeyon/js/jquery-1.3.2.min.js?4
Line 12

任何人都知道发生了什么事吗?
如果我在.each()语句之前发出警报就会发出警告,但是如果我在.each()语句中发出警报,我什么也得不到,变量永远不会被构建.

谢谢!

解决方法

你正在通过使用$.ajax()来做到这一点.使用$.getJSON()更容易.

大佬总结

以上是大佬教程为你收集整理的使用jQuery .each()解析JSON数组全部内容,希望文章能够帮你解决使用jQuery .each()解析JSON数组所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。