我正在开发来自 NiceHash api 的应用程序。我必须使用的 JSON 如下所示:
{
"result":{
"addr":"37ezr3FDDbPXWrCSKNfWzcxXZnc7qHiasj",
"workers":[
[ "worker1", { "a":"45.7" }, 9, 1, "32", 0, 14 ],
[ "worker1", { }, 5, 1, "100000", 0, 22 ],
]
"algo":-1
},
"method":"stats.provider.workers"
}
用于解析制作这样的结构
struct Root: Decodable {
var result: WorkersResult?
var method: String?
}
struct WorkersResult: Decodable {
var addr: String?
var workers: [Workers]?
var algo: Int?
}
struct Workers: Decodable {
var worker: [Worker]?
}
struct Worker: Decodable {
var name: String?
var hashrate: Hashrate?
var time: Int?
var XNSUB: Int?
var difficult: String?
var reject: Int?
var algo: Int?
}
struct Hashrate: Decodable {
var rate: String?
}
响应等于 nil,我不明白我做错了什么,我知道问题在于解析工人数组,因为如果我评论工人,响应等于一些有效数据。感谢帮助!