大佬教程收集整理的这篇文章主要介绍了请求 github Swift 的 api 要点,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我很难快速提出对 github API gist 的请求。以下是代码: 我想知道如何从 gist return 中获取这些数据以显示在屏幕上。
回复:(https://api.github.com/gists/95fcf71eb72f2ea1e3836d192c788ebC)
{
"url": "https://API.github.com/gists/95fcf71eb72f2ea1e3836d192c788ebc","forks_url": "https://API.github.com/gists/95fcf71eb72f2ea1e3836d192c788ebc/forks","commits_url": "https://API.github.com/gists/95fcf71eb72f2ea1e3836d192c788ebc/commits","ID": "95fcf71eb72f2ea1e3836d192c788ebc","node_ID": "MDQ6R2lzdDk1ZmNmNzFlYjcyZjJlYTFlMzgzNmQxOTJjNzg4ZWJj","git_pull_url": "https://gist.github.com/95fcf71eb72f2ea1e3836d192c788ebc.git","git_push_url": "https://gist.github.com/95fcf71eb72f2ea1e3836d192c788ebc.git","HTML_url": "https://gist.github.com/95fcf71eb72f2ea1e3836d192c788ebc","files": {
"gist.swift": {
"filename": "gist.swift","type": "text/plain","language": "Swift","raw_url": "https://gist.githubusercontent.com/arjdev69/95fcf71eb72f2ea1e3836d192c788ebc/raw/60db0c3f01cffdd56bcfd3474d19d533c02dc0f2/gist.swift","size": 2534,"truncated": false,"content": "//\n// SceneDelegate.swift\n//"
}
},"public": true,"created_at": "2021-04-21T00:48:19Z","updated_at": "2021-04-21T01:31:18Z","description": "Ios Gist App","comments": 1,"user": null,"comments_url": "https://API.github.com/gists/95fcf71eb72f2ea1e3836d192c788ebc/comments"....conTinue
}
型号:
import UIKit
struct GistModel: Decodable {
let ID@R_450_7101@g;
var files@R_450_7101@g;
let created_at@R_450_7101@g;
let updated_at@R_450_7101@g;
let comments:Int;
enum CodingKeys: String,CodingKey {
case files
case created_at
case updated_at
case comments
case ID
}
}
struct GistList: Decodable {
let all: [GistModel]
enum CodingKeys: String,CodingKey {
case all
}
}
API:
func getGistByID(_ ID@R_450_7101@g,completion:@escaPing(_ data:GistModel) -> VoID){
guard let url = URL(String: urlservice + "\(ID)") else {return}
let request = AF.request(url)
request.responseDecodable(of: GistModel.self) { (responsE) in
print(responsE)
guard let gist = response.value else { return }
completion(gist)
}
}
我在解码响应时遇到问题,尤其是“文件”属性。
这里是错误:
failure(Alamofire.AFError.responseserializationFailed(reason: Alamofire.AFError.ResponseserializationFailureReason.deCodingFailed(error: Swift.DeCodingError.typeMismatch(Swift.String,Swift.DeCodingError.Context(CodingPath: [CodingKeys(stringvalue: "files",intValue: nil)],deBUGDescription: "Expected to decode String but found a Dictionary instead.",underlyingError: nil)))))
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的请求 github Swift 的 api 要点全部内容,希望文章能够帮你解决请求 github Swift 的 api 要点所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。