这是从服务器返回的 json 字符串。我试图将其映射到对象映射器类并打印值,但出现以下错误。
Error Domain=NSCocoaErrorDomain Code=3840 "No string key for value in object around character 1."
{'Status': False, 'updatedStatus': True, 'connectionStatus': True}
下面是我的映射器类
public class Info: Mappable {
internal let kStatusKey: String = "Status"
internal let kConnectionStatusKey: String = "connectionStatus"
internal let kupdatedStatusKey: String = "updatedStatus"
// MARK: Properties
public var Status: String?
public var connectionStatus: String?
public var updatedStatus: String?
// MARK: ObjectMapper Initalizers
/**
Map a JSON object to this class using ObjectMapper
- parameter map: A mapping from ObjectMapper
*/
required public init?(_ map: Map){
}
/**
Map a JSON object to this class using ObjectMapper
- parameter map: A mapping from ObjectMapper
*/
public func mapping(map: Map) {
Status <- map[kStatusKey]
connectionStatus <- map[kConnectionStatusKey]
updatedStatus <- map[kUpdatedStatusKey]
}
}
我无法更改从服务器返回的字符串,有什么方法可以修复我的代码。 任何帮助将不胜感激。谢谢。
最佳答案
您的 JSON 应如下所示:
{
"status": false,
"updatedStatus": true,
"connectionStatus": true
}
据此更新您的映射器。
关于ios - 错误域=NSCocoaErrorDomain 代码=3840 "No string key for value in object around character 1.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39200690/