取得Yahoo及時匯率

1 篇文章 / 0 new
author
取得Yahoo及時匯率
透過 GET 向 Yahoo請求可取得所要的即時匯率資料, 格式如下
http://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.xchange where pair in ("USDEUR","USDTWD")&format=json&env=store://datatables.org/alltableswithkeys&callback=JSON_CALLBACK

►兩個比較重要的參數
1. 匯率清單, ("USDEUR","USDTWD")
2. 資料封裝 callback=JSON_CALLBACK 表示回傳的資料外加 JSON_CALLBACK( JSON-Data ), 名稱自訂

► 回傳資料為 JSON 格式
{
    "query": {
        "count": 2,
        "created": "2014-02-21T01:24:33Z",
        "lang": "zh-tw",
        "results": {
            "rate": [
                {
                    "id": "USDEUR",
                    "Name": "USD to EUR",
                    "Rate": "0.7291",
                    "Date": "2/21/2014",
                    "Time": "8:20pm",
                    "Ask": "0.7291",
                    "Bid": "0.7291"
                },
                {
                    "id": "USDTWD",
                    "Name": "USD to TWD",
                    "Rate": "30.329",
                    "Date": "2/21/2014",
                    "Time": "8:20pm",
                    "Ask": "30.334",
                    "Bid": "30.324"
                }
            ]
        }
    }
}
使用 callback 參數
JSON_CALLBACK({"query":{"count":2,"created":"2014-02-21T01:21:09Z","lang":"zh-TW","results":{"rate":[{"id":"USDEUR","Name":"USD to EUR","Rate":"0.729","Date":"2/21/2014","Time":"8:16pm","Ask":"0.729","Bid":"0.729"},{"id":"USDTWD","Name":"USD to TWD","Rate":"30.335","Date":"2/21/2014","Time":"8:17pm","Ask":"30.353","Bid":"30.317"}]}}});
Free Web Hosting