Comments (4)
Please provide some more info so we can help. Your code and the JSON string you are trying to parse would help
from objectmapper.
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.
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.
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)
- Array of Dictionary mapping
- check the value for parse HOT 2
- XCODE 12.0 Could not find module 'ObjectMapper' for target 'arm64-apple-ios-simulator'; HOT 3
- keep the original order mapping and array
- Eventual crashing HOT 2
- Object converting to JSON is not working properly (Object.toJSON() or Object.toJSONString(prettyPrint: true))
- Module compiled with Swift 5.2.4 cannot be imported by the Swift 5.5.1 compiler, Xcode 13.1 Error
- hope support the "|" separator
- Undefined vs. nil HOT 1
- Map.subscript(key:nested:delimiter:ignoreNil:). crash
- Privacy manifest HOT 4
- Not working in Xcode 15 HOT 3
- Add Privacy Manifest HOT 2
- XCode 15 and Swift5 Error Please Update the Library to Swift 5
- Cannot install via SPM, error: Invalid manifest HOT 7
- pod not found 4.3.0 HOT 1
- // swift-tools-version:5.0 doesn't work under Xcode 15 HOT 4
- 4.4.X minimum version iOS 17.0 HOT 1
- Current Package.swift config does not work HOT 1
- How to use Generic,like HandyJSON?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from objectmapper.