我正在制作这样一个视频的应用程序:https ://www.youtube.com/watch?v=mzyFQ55M7eo
但我不希望 textview 显示 json 数据,我只希望它显示文本“Hello(用户名)”意思是 Hello(subject_id),但我不知道如何像视频一样用 alamofire 解析 json。我正在研究这个,但没有运气。有人可以解释怎么做吗?在此先感谢并为我的英语不好感到抱歉。
我正在制作这样一个视频的应用程序:https ://www.youtube.com/watch?v=mzyFQ55M7eo
但我不希望 textview 显示 json 数据,我只希望它显示文本“Hello(用户名)”意思是 Hello(subject_id),但我不知道如何像视频一样用 alamofire 解析 json。我正在研究这个,但没有运气。有人可以解释怎么做吗?在此先感谢并为我的英语不好感到抱歉。
编写一个函数来获取json数据。如果它的 Post 方法
let todosEndpoint: String = Your Url
let paramss: Parameters = ["user_id": self.userId]
Alamofire.request(
todosEndpoint,
method: .post,
parameters: paramss,
headers: ["Content-Type": "application/x-www-form-urlencoded"])
.responseJSON { response in
switch response.result {
case .success:
//if json data is a array
let json = JSON(response.result.value as Any)
if let codes = json.array {
for eachCode in codes {
let userName = eachCode["username"].stringValue
print("userName is\(userName)")
}
}
break
case .failure:
break
}
}