UserInterest类:
class UserInterest: Mappable {
var id: String?
var userId: String?
var interestId: String?
init() {
}
required init?(map: Map) {
}
// Mappable
func mapping(map: Map) {
id <- map["ID"]
userId <- map["UserId"]
interestId <- map["InterestId"]
}
}
UserInterestAPI类:
class UserInterestAPI: Mappable {
var userInterestList: [UserInterest]?
init() {
}
required init?(map: Map) {
}
// Mappable
func mapping(map: Map) {
userInterestList <- map["UserInterestList"]
}
}
我正在使用Alamofire
进行网络调用,使用ObjectMapper
进行JSON解析。当我解析UserInterestAPI然后它解析如下。
["UserInterestList":
[
["ID": "1242fecd-9be6-49c5-96ed-0176dbe432b3", "InterestId": "998e1bec-e597-4c1f-9411-892eac780673", "UserId": "105536f2-ace8-43d4-8b53-32c245bea22d"],
["ID": "fbff0439-83ee-4155-8987-7f3589bf76da", "InterestId": "c43d5161-89b8-41d1-be7f-b3ecb60d2347", "UserId": "105536f2-ace8-43d4-8b53-32c245bea22d"]
]
]
预期请求:(适用于邮递员或提琴手)
{"UserInterestList":
[
{"ID": "1242fecd-9be6-49c5-96ed-0176dbe432b3", "InterestId": "998e1bec-e597-4c1f-9411-892eac780673", "UserId": "105536f2-ace8-43d4-8b53-32c245bea22d"},
{"ID": "fbff0439-83ee-4155-8987-7f3589bf76da", "InterestId": "c43d5161-89b8-41d1-be7f-b3ecb60d2347", "UserId": "105536f2-ace8-43d4-8b53-32c245bea22d"}
]
}
所以在我的API方法中,我没有得到大小为2的列表,而是我将列表大小设置为0.我认为这是因为 [而不是 {用于解析的JSON中的项目。请帮我解决这个问题。