无法下载&从JSON文件解析Google趋势

时间:2013-07-17 01:30:58

标签: javascript json jquery

我发现此网址为您提供了Google趋势json文件:

http://www.google.com/trends/fetchComponent?cid=TIMESERIES_GRAPH_0&export=3&q=javascript&geo=US < - 此趋势链接显示了javascript这个词的美国搜索趋势历史记录。

我无法解析它并将其转换为我可以使用的对象。现在我开始怀疑它甚至是可能的,因为它不是真正的API而是原始文件。

我有一个朋友帮我建立一个快速测试,但它也没有工作。

最终结果目标:

我只是希望能够通过json获取所有数据,让javascript解析它并在控制台中打印数据

这是代码

<html>
<head>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
  <script>

    var url = 'http://www.google.com/trends/fetchComponent?cid=TIMESERIES_GRAPH_0&export=3&q=bread&cat&geo=US';

    var jsonObject;

    var google = {
      visualization : {
        Query : {
          setResponse: function(json) {
            jsonObject = json;
          }
        }
      }
    };

    console.log('Making ajax request ...');
    $.ajax({ dataType: 'text', url: url })

      // When it arrives, pull out the JSON using the function we setup on
      // line 16
      .done(function(data) {
        console.log('Data has arrived! Executing it to get the JSON from it ...');
        eval(data);
        console.log(jsonObject);
      })

      // If the request fails, print out the reason why.
      .fail(function(jqXHR, textStatus) {
        console.log("The ajax request failed: " + textStatus );
      });

  </script>
</body>

谢谢!!!

-Nico

0 个答案:

没有答案