swift - Alamofire 3.3 JSON ObjectMapping -
i'm using alamofire 3.3 in swift 2
edited question after more research..
i think mapping wrong, have no idea how should change it. can see snippets use key->value elements try map dont have tell mapping go 1 level lower? , if how should go it?
keys changing, how can map such things?
[old question]
strange markup response rest service json code correct use elsewhere, join snippet of how service sends , how function receives use object mapper, posted under func
removed if around mapping part , got error:
fatal error: unexpectedly found nil while unwrapping optional value
func getpanden(url:nsurl, success:(value:[pand])->(), failed:(value:nserror)->()) { alamofire.request(.get, "\(base_url)\(url)").responsejson { response in if let json = response.result.value { print(response) if json.count >= 1 { // print(json); if let panden:array<pand> = mapper<pand>().maparray(json) { //use var transform else let success(value: panden) } } else { failed(value:nserror( domain: "ehb.pulseapp.watchkitapp.watchkitextension" ,code: -10 ,userinfo: [nslocalizedfailurereasonerrorkey: "error.data.status.not.found"])) } } } }
the mapping:
func mapping(map: map) { pand_id <- map["pand_id"] name <- map["name"] street <- map["street"] city <- map["city"] zip <- map["zip"] country <- map["country"] geolocation_lat <- map["geolocation_lat"] geolocation_long <- map["geolocation_long"] image <- map["image"] }
how json looks in browser:
{ "pand_2": { "pand_id": "21", "name": "ludovic marchand", "street": "victor mertensstraat 13", "city": "hoeilaart", "zip": "1560", "country": "belgium", "geolocation_lat": "2", "geolocation_long": "3", "image": "1460980598349.png" }, "pand_3": { "pand_id": "22", "name": "chez chloƩ", "street": "groenstraat 36", "city": "zaventem", "zip": "1930", <-------see how there quotes around elements "country": "belgium", "geolocation_lat": "50.8869256", "geolocation_long": "4.4652817", "image": "1460980775092.jpg" }, <--- how should ... }
and here how looks when alamorfire receives it:
{ "pand_2" = { city = hoeilaart; country = belgium; "geolocation_lat" = 2; "geolocation_long" = 3; image = "1460980598349.png"; name = "ludovic marchand"; "pand_id" = 21; street = "victor mertensstraat 13"; zip = 1560; }; "pand_3" = { city = zaventem; country = belgium; "geolocation_lat" = "50.8869256"; "geolocation_long" = "4.4652817"; image = "1460980775092.jpg"; name = "chez chlo\u00e9"; "pand_id" = 22; street = "groenstraat 36"; zip = 1930; <---- zip should "zip" }; <---- should , ... }
Comments
Post a Comment