2012-01-25 75 views
0

因爲我可以用Jquery解析這個查詢YQL。 我無法看到的信息 非常感謝你用Jquery解析貨幣YQL

的Json

{ 
"query": { 
    "count": 2, 
    "created": "2012-01-25T18:58:01Z", 
    "lang": "en-US", 
    "results": { 
    "span": [ 
    { 
    "id": "yfs_l10_audmxn=x", 
    "content": "13.8172" 
    }, 
    { 
    "id": "yfs_l10_audmxn=x", 
    "content": "13.8172" 
    } 
    ] 
    } 
} 
} 

jQuery的

 <script> 
     $(function(){ 
      $.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fmx.finance.yahoo.com%2Fq%3Fs%3DAUDMXN%3DX%22%20and%0A%20%20%20%20%20%20xpath%3D'%2F%2F*%5B%40id%3D%22yfs_l10_audmxn%3Dx%22%5D'&format=json&callback=", function(data){ 
       $('#currency').html(data.query['results'].span); 
      }); 
     }); 
    </script> 

TNKS =)

+0

問題在哪裏? – Treffynnon

回答

1

貨幣信息在那裏。我不知道你爲什麼看不到它。
可能是你應該使用這個,

$('#currency').html(data.query['results'].span[0].content); 

data.query['results'].span[0].content包含13.8172
那就是說MXN 1 = AUD 13.8172

+0

非常感謝你muc。我工作正常 – yorkfx

0
$(function(){ 
      $.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fmx.finance.yahoo.com%2Fq%3Fs%3DAUDMXN%3DX%22%20and%0A%20%20%20%20%20%20xpath%3D'%2F%2F*%5B%40id%3D%22yfs_l10_audmxn%3Dx%22%5D'&format=json&callback=", function(data){ 
     $("span").html(data.query.count); 
     $("#created").html(data.query.created); 
     $("#lang").html(data.query.lang); 
$(data.query.results.span).each(function(index,elem){ 
$.each(elem,function(k,v){ 
    $("<tr/>").append("<td> "+k+" </td><td> "+v+" </td>").appendTo("table"); 
    }) 
    }); 
    }); 
}); 

DEMO

+0

非常感謝你 – yorkfx

+0

不客氣 – Rafay