Ios 在swift4中使用JSONDECODATABLE时出错?

Ios 在swift4中使用JSONDECODATABLE时出错?,ios,json,swift,swift4,jsondecoder,Ios,Json,Swift,Swift4,Jsondecoder,在swift4中使用JSONDECODATABLE时出现以下错误“类型UserRegister不符合协议‘可解码’” 我的模型结构是这样的 struct UserRegister: Decodable { let id : NSInteger let name : String? let email : String? let cities : Array<Any>? let tax : [tax] let username : [us

在swift4中使用JSONDECODATABLE时出现以下错误<代码>“类型UserRegister不符合协议‘可解码’”

我的模型结构是这样的

struct UserRegister: Decodable {
    let id : NSInteger
    let name : String?
    let email : String?
    let cities : Array<Any>?
    let tax : [tax]
    let username : [username]
}

struct tax : Decodable {
    let deviceId : NSInteger?
    let financialYear : String?
    let country : String?
    let name : String?
    let state : String?
    let taxCode : String?
    let value : NSInteger? 
}

struct username : Decodable {
    let email : String?
    let phone : String?
}
struct UserRegister:可解码{
让id:NSInteger
名称:字符串?
让电子邮件:字符串?
让城市:阵列?
出租税:[税]
让用户名:[用户名]
}
结构税:可解码{
让设备ID:NSInteger?
让财政年度:字符串?
让国家:弦?
名称:字符串?
让状态:字符串?
让taxCode:String?
让值:NSInteger?
}
结构用户名:可解码{
让电子邮件:字符串?
让电话:字符串?
}

问题在于
数组。您需要一个可解码类型的数组,如字符串或Int。

您的代码中没有类型
xxxxx
,因此我怀疑错误是否与您所说的相符。现在编辑问题。另外,请以大写字母开头类型的名称,如
tax
username
,用户名。尝试了这个,但仍然得到相同的错误,将NSInteger转换为Int.@matt+@Zac24还有
Array
@staticVoidMan是的,事实证明仅此而已。是的,这就解决了问题。我知道我们在是否结束投票和回答问题上存在分歧–但是(假设结束投票是你的):如果OP编辑了这个问题,你回答了,那你为什么不撤回最后一票?