获取天气接口数据
var url = 'https://tianqiapi.com/api?version=v6&appid=21317937&appsecret=ldA3yCrE'; $.getJSON(url, function (res) { console.log(traditional(res)); console.log(traditional(res.city)); console.log(traditional(res.wea)); console.log(res.tem); })
转化为繁体
function traditional(words) { switch (words) { case "多云": return "多雲"; break; case "阴": return "陰"; break; case "阵雨": return "陣雨"; break; /*地区名称*/ case "台北": return "臺北"; break; case "桃园": return "桃園"; break; case "宜兰": return "宜蘭"; break; case "台中": return "臺中"; break; case "云林": return "雲林"; break; case "嘉义": return "嘉義"; break; case "台南": return "臺南"; break; case "屏东": return "屏東"; break; case "花莲": return "花蓮"; break; case "台东": return "臺東"; break; case "金门": return "金門"; break; case "连江": return "馬祖"; break; /*無需轉化*/ default: return words; } }
lockdatav Done!