【问题标题】:Cannot access objects from Yahoo Boss YQL Response Data无法从 Yahoo Boss YQL 响应数据访问对象
【发布时间】:2015-04-06 02:59:46
【问题描述】:

我在访问 Yahoo Boss YQL Json 响应数据中的任何对象时遇到很多问题。我用过这个YQL Console for Boss Search Tables

这是我所做的:

<!DOCTYPE HTML>
<html>
<head>
<script src="http://code.jquery.com/jquery-2.0.3.min.js" type="text/javascript"></script>
<script type="text/javascript">

var url = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20boss.search%20where%20service%20%3D%22images%22%20AND%20count%3D%221%22%20AND%20q%3D%22iphone6%22%20AND%20ck%20%3D%20%22MYCONSUMER_KEY%22%20AND%20secret%3D%22MYCONSUMER_SECRET%22%3B&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";


(function showPix()
      {
          $.getJSON(url, function (data)
        {
          console.log(data);
          var myObj = data.results.bossresponse.images.results.result.clickurl;
          $.each(myObj, function ()
          {
            $('#pix').append(this);
          });
        });
      })();

</script>
</head>

<body>
    <div id="pix">
    </div>
    <button onclick="showPix();">run</button>

</body>
</html>

console.log();给了我一个包含图像的对象,但我无法在屏幕上显示图像。它告诉我 showPix 是未定义的。任何帮助将不胜感激。 TIA

【问题讨论】:

    标签: yahoo-boss-api


    【解决方案1】:

    我是这样想的:

    <html>  
          <head><title>YQL and RSS: Yahoo Top News Stories</title>  
          <style type='text/css'>  
            #results{ width: 40%; margin-left: 30%; border: 1px solid gray; padding: 5px; height: 200px; overflow: auto; }   
          </style>  
          <script type='text/javascript'>  
            // Parses returned response and extracts  
            // the title, links, and text of each news story.  
            function top_stories(o){  
              var items = o.query.results.item;  
              var output = '';  
              var no_items=items.length;  
              for(var i=0;i<no_items;i++){  
                var title = items[i].title;  
                var link = items[i].link;  
                var desc = items[i].description;  
                output += "<h3><a href='" + link + "'>"+title+"</a></h3>" + desc + "<hr/>";  
              }  
              // Place news stories in div tag  
              document.getElementById('results').innerHTML = output;    
            }  
            </script>  
          </head>  
          <body>  
            <!-- Div tag for stories results -->  
            <div id='results'></div>  
            <!-- The YQL statment will be assigned to src. -->  
            <script src='https://query.yahooapis.com/v1/public/yql?q=select%20title%20from%20rss%20where%20url%3D%22http%3A%2F%2Frss.news.yahoo.com%2Frss%2Ftopstories%22&format=json&callback=top_stories'></script>  
          </body> 
    

    【讨论】:

      猜你喜欢
      • 2018-01-03
      • 1970-01-01
      • 1970-01-01
      • 2014-01-21
      • 2017-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-07
      相关资源
      最近更新 更多