Error Domain=NSCocoaErrorDomain Code=3840 "No string key for value in object around character 1."

user6587892 picture user6587892 · Aug 29, 2016 · Viewed 8.4k times · Source

This is the json string returned from a server. I am trying to Map it to a object mapper class and print values but I get the following error.

Error Domain=NSCocoaErrorDomain Code=3840 "No string key for value in object around character 1."

{'Status': False, 'updatedStatus': True, 'connectionStatus': True}

And following is my mapper class

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]

    }
}

I cannot change the string returned from the server, Is there any way I can fix my code. Any help will be appreciated. Thank you.

Answer

aytek picture aytek · Aug 29, 2016

Your JSON should look like this:

{
    "status": false,
    "updatedStatus": true,
    "connectionStatus": true
}

Update your mapper upon this.