Giter Site home page Giter Site logo

parse integer response always nil (e.g status = 200) the result is always becomes nil .. any help ? thanks about objectmapper HOT 4 CLOSED

tristanhimmelman avatar tristanhimmelman commented on July 26, 2024
parse integer response always nil (e.g status = 200) the result is always becomes nil .. any help ? thanks

from objectmapper.

Comments (4)

tristanhimmelman avatar tristanhimmelman commented on July 26, 2024

Please provide some more info so we can help. Your code and the JSON string you are trying to parse would help

from objectmapper.

rjjohnpatrickcruz avatar rjjohnpatrickcruz commented on July 26, 2024

Hey,

here is the sample json string im trying to parse
{
"completed_in" = "0.0919";
message = "Login Successful";
profile = {
"current_coordinates" = "";
email = "[email protected]";
fname = Juan;
id = 83;
lname = "Dela Cruz";
mname = Gitna;
"mobile_no" = 09090909090;
photo = "";
};
"security_key" = "4DB585AD-F0D2-28AB-68A7-5F4C43A55051";
status = 1;
}

---- swift code (using object mapper)----
let user = Mapper().map(JSON!)

---- swift code (my object mapper classes) ----

class User: Mappable {

var completed_in: String?
var status: String?
var message: String?
var security_key: String?
var profile: Profile?

required init(){}

// MapperProtocol
func mapping(mapper: Map) {
    completed_in <= mapper["completed_in"]
    status <= mapper["username"]
    message <= mapper["message"]
    security_key <= mapper["security_key"]
    profile <= mapper["profile"]
}

}

class Profile : Mappable {

var id : Int?
var email: String?
//var salt: String?
var fname: String?
var lname: String?
var mname: String?
var mobile: String?
var address: String?
var photo: String?
var current_coordinates: String?

required init(){}

// MapperProtocol
func mapping(mapper: Map) {
    id <= mapper["id"]
    email <= mapper["email"]
    fname <= mapper["fname"]
    lname <= mapper["lname"]
    mname <= mapper["mname"]
    mobile <= mapper["mobile"]
    address <= mapper["address"]
    photo <= mapper["photo"]
    current_coordinates <= mapper["current_coordinates"]

}

}

from objectmapper.

tristanhimmelman avatar tristanhimmelman commented on July 26, 2024

Hi, you're models look properly formed but your JSON is not. You can test if JSON is properly formed using online tools like: http://jsonformatter.curiousconcept.com/

I've reformatted your JSON properly below.

{
"completed_in" : 0.0919,
"message" : "Login Successful",
"profile" : {
    "current_coordinates" : "",
    "email" : "[email protected]",
    "fname" : "Juan",
    "id" : 83,
    "lname" : "Dela Cruz",
    "mname" : "Gitna",
    "mobile_no" : "09090909090",
    "photo" : ""
},
"security_key" : "4DB585AD-F0D2-28AB-68A7-5F4C43A55051",
"status" : 1
}

The other issue I see is that you need to pass in a type when you are creating a Mapper object.

Mapper<User>().map(string: JSONString)

Hope this helps

from objectmapper.

rjjohnpatrickcruz avatar rjjohnpatrickcruz commented on July 26, 2024

Hi thanks , i think i see the issue.. im using alamofire to request the json and the json response is not a valid json format ..
thanks!

from objectmapper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.