正如您所提到的,99% 的 API 是付费服务或功能有限。但我更喜欢使用的仍然是
https://www.wordsapi.com/
使用 wordapi 的基本版(未付费版),您每天最多可以拨打 2500 次电话。我建议您使用相同的,直到您的应用程序得到一些认可。稍后,如果您觉得您的应用程序即将产生更多负载,您可以更新到有意义的付费版本。
只需将示例请求放在如何快速制作相同的内容上。更换
地图键
和你的
wordsApiKey
let string = "https://wordsapiv1.p.mashape.com/words/stack/synonyms"
let url = NSURL(string: string)
let request = NSMutableURLRequest(URL: url!)
request.setValue("MapKey", forHTTPHeaderField: "X-Mashape-Key")
request.HTTPMethod = "GET"
let session = NSURLSession.sharedSession()
let request = session.dataTaskWithRequest(request) { (data, response, error) -> Void in
if let resp = response as? NSHTTPURLResponse {
// Do what you want to do with your response.
}
}
request.resume()
将我得到的响应放在我试图搜索的单词“stack”上。(我尝试使用 curl 命令来获得响应)
{
"word": "stack",
"synonyms": [
"smokestack",
"push-down list",
"push-down stack",
"heap",
"pile",
"push-down storage",
"push-down store",
"batch",
"deal",
"flock",
"good deal",
"great deal",
"hatful",
"lot",
"mass",
"mess",
"mickle",
"mint",
"mountain",
"muckle",
"passel",
"peck",
"plenty",
"pot",
"quite a little",
"raft",
"sight",
"slew",
"spate",
"tidy sum",
"wad"
]
}
除了反义词、定义、示例等同义词之外,您还可以使用它的其他功能。希望这个有帮助。