使用JQuery getJSON方法 [英] Using JQuery getJSON method

查看:103
本文介绍了使用JQuery getJSON方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用JQuery getJSON函数插入JSON数据. REST查询是:

I am attempting to pase a a JSON data using the JQuery getJSON function. The REST query is:

http://query.yahooapis.com/v1/public/yql?q=select%20woeid%20from%20geo.places%20where%20text%20%3D%20%22london%22&format=json&jsoncallback=?

我用来解析数据"以获取WOEID值的脚本在下面似乎不起作用:

The script I'm using to parse 'data' to obtain the WOEID value doesnt seem to work below:

 $.getJSON("http://query.yahooapis.com/v1/public/yql?"+
                "q=select%20woeid%20from%20geo.places%20where%20text%20%3D%20%22"+
                "london"+
                "%22&format=json&jsoncallback=?",
        function(data){
  console.log("json: " + data);
  var datatmp = data;
          if(data.results[0]){
            var data = filterData(data.results.place[0]);
           }
         }
       );

有人可以说我在做什么错吗? 链接文本

Can anyone say what I'm doing wrong? link text

推荐答案

您的代码需要一些调整,这是更新版本:

Your code needed a few tweaks, here's an updated version:

$.getJSON("http://query.yahooapis.com/v1/public/yql?"+
      "q=select%20woeid%20from%20geo.places%20where%20text%20%3D%20%22"+
      "london"+
      "%22&format=json&jsoncallback=json",
      function(data){
          if(data.query.results){
              $.each(data.query.results.place, function(i, v) {
                  console.log("woeid #" + i + ": " + v["woeid"]);
              });
          }
      });​

results对象位于query下面,因此您需要首先进入该位置,上面的代码遍历返回的第一个位置的woeid并警告它们...这只是一个开始,不确定您要做什么最终想使用woeid,但是希望这可以帮助您入门. 您可以在此处看到上面的代码.

The results object is beneath query, so you need to go into there first, the above code iterates through the woeid's of the first place returned and alerts them...it's just a starter, not sure what you ultimately wanted to do with the woeid but hopefully this will get you started. You can see the above code working here.

这篇关于使用JQuery getJSON方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆