快速错误:类型 _ 的值没有成员 _
这是我使用 api 的代码:
struct everything: Codable{
let topic: String
let content: String
let category: String
let time: String
let price: String
let prize: String
}
struct parsingss : Codable {
let scrims: [everything]
}
@IBOutlet weak var prizeLabel: UILabel!
@IBOutlet weak var priceLabel: UILabel!
@IBOutlet weak var timeLabel: UILabel!
@IBOutlet weak var categoryLabel: UILabel!
@IBOutlet weak var ContentLabel: UILabel!
@IBOutlet weak var TopicLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
if let url = URL(string: "http://{Local-Host}/post") {
URLSession.shared.dataTask(with: url) { data, response, error in
if let data = data {
let jsonDecoder = JSONDecoder()
do {
let parsedJSON = try jsonDecoder.decode(parsingss.self, from: data)
print(parsedJSON)
DispatchQueue.main.async {
self.TopicLabel.text = parsedJSON.topic
self.ContentLabel.text = parsedJSON.content
self.categoryLabel.text = parsedJSON.category
self.timeLabel.text = parsedJSON.time
self.priceLabel.text = parsedJSON.price
self.prizeLabel.text = parsedJSON.prize
}
}
catch {
print(error)
}
}
}.resume()
}
}
}
“错误:‘testViewController.parsingss’类型的值没有成员‘topic’”
无论哪种方式,回复一些代码都会更好。感谢开发者。
如果没有“尝试在标签中打印”,结果就会输出。它在一个数组中:
[ scrims: {
"topic": "tv",
"content": "done",
"category": "gg",
"time": "10pm",
"price": "Rs.100",
"prize": "Rs.1000",
"id": 1
},
{
"topic": "1",
"content": "d1",
"category": "g1",
"time": "10pm",
"price": "Rs.11",
"prize": "R1",
"id": 2
} ]
谢谢!
how do I fix this error? xcodes-13
This Is my code for working with api:
struct everything: Codable{
let topic: String
let content: String
let category: String
let time: String
let price: String
let prize: String
}
struct parsingss : Codable {
let scrims: [everything]
}
@IBOutlet weak var prizeLabel: UILabel!
@IBOutlet weak var priceLabel: UILabel!
@IBOutlet weak var timeLabel: UILabel!
@IBOutlet weak var categoryLabel: UILabel!
@IBOutlet weak var ContentLabel: UILabel!
@IBOutlet weak var TopicLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
if let url = URL(string: "http://{Local-Host}/post") {
URLSession.shared.dataTask(with: url) { data, response, error in
if let data = data {
let jsonDecoder = JSONDecoder()
do {
let parsedJSON = try jsonDecoder.decode(parsingss.self, from: data)
print(parsedJSON)
DispatchQueue.main.async {
self.TopicLabel.text = parsedJSON.topic
self.ContentLabel.text = parsedJSON.content
self.categoryLabel.text = parsedJSON.category
self.timeLabel.text = parsedJSON.time
self.priceLabel.text = parsedJSON.price
self.prizeLabel.text = parsedJSON.prize
}
}
catch {
print(error)
}
}
}.resume()
}
}
}
"error : Value of type 'testViewController.parsingss' has no member 'topic'"
Reply with some codes would be better either ways. Thanks developers.
Without "trying to print in label", the result does come to the output. it is in an array:
[ scrims: {
"topic": "tv",
"content": "done",
"category": "gg",
"time": "10pm",
"price": "Rs.100",
"prize": "Rs.1000",
"id": 1
},
{
"topic": "1",
"content": "d1",
"category": "g1",
"time": "10pm",
"price": "Rs.11",
"prize": "R1",
"id": 2
} ]
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您试图在不指定索引的情况下从数组对象分配下标值。
试试这个:
}
You are trying to assign the subscript values from an array object without specifying the index.
Try this:
}