gpt4 book ai didi

ios - 在 token Swift 4 中检索值键后在应用程序中显示姓氏

转载 作者:行者123 更新时间:2023-11-30 11:17:45 26 4
gpt4 key购买 nike

继上一篇文章之后,我遇到了另一个问题。

我想在检索 token 值后在应用程序中显示姓氏。这是我的代码,用于获取 token 中姓氏的值

// request = url of API 
// token = I have already recovered the value of the token
request.addValue("Bearer \(token!)", forHTTPHeaderField: "Authorization")
//get information in token
URLSession.shared.dataTask(with: request) { (data, response, error) in
guard let data = data else { return }
do {
let json = try JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableContainers) as! [String: AnyObject]
let sub = json["sub"] as! [String: AnyObject]
// get value of lastName
let lastName = sub["lastname"] as! String

} catch {
print("error")
}
}.resume()

现在我想在应用程序中显示姓氏

    let headerMenu = HPMenuHeaderViewModel.init(lastName: "display lastname here..")
// display table view and information of user like lastname
let tableViewModel = HPMenuViewModel(titlePage: "Menu", array: arrayCellModel, headerMenuViewModel: headerMenu)
self.tableViewModel = tableViewModel

你能帮我吗?

最佳答案

我有这个功能来获取名字、姓氏、号码

func loadMemberProfil(){
let token = HPWSLoginManager.shared().saveSuccessResponse.token
let url = URL(string: "http://51.38.36.76:40/api/v1/profile")
var request = URLRequest(url: url!)
request.httpMethod = "GET"
request.addValue("Bearer \(token!)", forHTTPHeaderField: "Authorization")
//get information in token
URLSession.shared.dataTask(with: request) { (data, response, error) in
guard let data = data else { return }
do {
let json = try JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableContainers) as! [String: AnyObject]
let sub = json["sub"] as! [String: AnyObject]
let firstName = sub["firstname"] as! String
let lastName = sub["lastname"] as! String
let number = sub["internationalFormat"] as! String
} catch {
print("error")

}
}.resume()
}

在 viewDidLoad() 中我想在此函数中显示

func initTableViewModel() {
let headerMenu = HPMenuHeaderViewModel.init(firstName: "...", lastName: "...", numberString: "...")
let tableViewModel = HPMenuViewModel(titlePage: "Menu", array: arrayCellModel, headerMenuViewModel: headerMenu)
self.tableViewModel = tableViewModel
}

关于ios - 在 token Swift 4 中检索值键后在应用程序中显示姓氏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51591914/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com