gpt4 book ai didi

ios - 如何使用 ObjectMapper 映射这个简单的 JSON

转载 作者:行者123 更新时间:2023-11-30 13:20:40 25 4
gpt4 key购买 nike

我有这个简单的 JSON,但我无法使用 ObjectMapper 映射它

{"response":404}

我就是这样做的

import Foundation
import UIKit
import ObjectMapper

class YASEmail: Mappable {

var response: String

required init?(_ map: Map) {
response = ""
}

func mapping(map: Map) {
response <- map["response"]
}
}

这就是我尝试绘制 map 的方式

if let response = Mapper<YASEmail>().map(result) {
print(response)
}

最佳答案

我已经更新了您的代码。请尝试这个

import Foundation
import ObjectMapper

class YASEmail: Mappable {

var response : AnyObject
required init?(_ map: Map) {
response = ""

}

func mapping(map: Map) {
response = map.JSONDictionary["response"]!
}
}

并尝试像这样映射:

if let response = Mapper<YASEmail>().map(jsonString) {
print(response.response)
}

关于ios - 如何使用 ObjectMapper 映射这个简单的 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37783052/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com