ios - How to download image from JSON using the Swift 3 and Alamofire? -
how download image json using alamofire , swift 3? getting dictionary of data. see following json response. able print data in labels can't download image. response getting api.
userjson userjson userjson userjson ["status": 1, "student": { "admission_date" = "14/06/2017"; "admission_no" = 13538; "class_teacher" = "caroline forbes"; dob =
"04/05/2001"; email = "ranisagar.sivadas@gmail.com"; "father_name" = "sagar sivadas"; gender = male; image =
"/system/images/86/j1f9diji_medium.jpg?1504593436"; "mother_name" = "rani r s"; name = "abhijith sagar"; phone = 9066260799; religion = hindu; "school_email" = "13538.861@demo.in"; "student_id" = 86; },
"message": details fetched successfully.]
this code.
func setupuiprofiledata() { apimanager.sharedinstance.getparentdatafromurl(){(userjson)-> void in let swiftyjsonvar = json(userjson) print("userjson userjson userjson userjson",userjson) print("swiftyjsonvar",swiftyjsonvar) let message = swiftyjsonvar["message"].rawstring() let sudent = swiftyjsonvar["student"].rawstring()! let jsondata = sudent.data(using: .utf8)! let dictionary = try? jsonserialization.jsonobject(with: jsondata, options: []) as! dictionary<string, any> self.name_lbl.text = dictionary?["name"] as? string self.fathername_lbl.text = dictionary?["father_name"] as? string self.mothername_lbl.text = dictionary?["mother_name"] as? string self.phone_lbl.text = dictionary?["phone"] as? string self.email_lbl.text = dictionary?["email"] as? string self.dob_lbl.text=dictionary?["dob"] as? string self.gender_lbl.text=dictionary?["gender"] as? string self.religion_lbl.text=dictionary?["religion"] as? string self.admissiondate_lbl.text=dictionary?["admission_date"] as? string self.admissionnum_lbl.text=dictionary?["admission_no"] as? string self.schoolmail_lbl.text=dictionary?["school_email"] as? string self.teacher_lbl.text=dictionary?["class_teacher"] as? string } }
have @ below code need pass link url alamofire , can download image . if not expected answer please re edit question .
let strurl1:string = "https://www.planwallpaper.com/static/images/9-credit-1.jpg" alamofire.request(strurl1).responsedata(completionhandler: { response in debugprint(response) debugprint(response.result) if let image1 = response.result.value { let image = uiimage(data: image1) self.imageview.image = image } })
i looked @ output had provided getting
image = "/system/images/86/j1f9diji_medium.jpg?1504593436";
is valid url or path if url need add base url + " /system/images/86/j1f9diji_medium.jpg?1504593436"
, pass alamofire block download image in above example
"https://www.planwallpaper.com" - baseurl "static/images/9-credit-1.jpg" - image path in case
hope helps.
Comments
Post a Comment