ios - Getting UIImage to work from JSON -
i'm having issue getting uiimage work json received. here let's take @ json
[ { node_title: "fumi", node_uid: "11", users_node_name: "pae", nid: "7", body: "<p>this fumi restaurant</p> ", enterprise address: "99/9", enterprise email: "fumi@gmail.com", enterprise tel: "08111111", enterprise logo: "<img typeof="foaf:image" src="http://localhost/drupal/sites/default/files/fumi.jpg" width="300" height="300" alt="" />" }, { node_title: "fuji", node_uid: "8", users_node_name: "testent", nid: "1", body: "<p>fuji</p> ", enterprise address: "somwhere belong", enterprise email: "ent1@mail.com", enterprise tel: "02-999-9999", enterprise logo: "<img typeof="foaf:image" src="http://localhost/drupal/sites/default/files/fuji.png" width="320" height="320" alt="" />" } ]
and here code: i'm able json received , show them on viewcontroller. however, [self.detail valueforkey:@"enterprise logo"] doesn't seems work due content of json.
btw, self.detail json object passed previous uitableviewcontroller doing preparedtosegue.
- (void)viewdidload { [super viewdidload]; self.enterprisename.text = [self.detail valueforkey:@"node_title"]; self.enterprisetel.text = [self.detail valueforkey:@"users_node_name"]; self.enterprisebody.text = [self.detail valueforkey:@"body"]; self.enterpriseemail.text = [self.detail valueforkey:@"nid"]; [self.piclogo setimagewithurl:[nsurl urlwithstring:[self.detail valueforkey:@"enterprise logo"]]]; }
i try method works fine content in enterprise logo must contain url of img only. i'm trying things dynamic as possible, don't expect static answer. there way me fix issue ?
[self.piclogo setimagewithurl:[nsurl urlwithstring:@"http://localhost/drupal/sites/default/files/fumi.jpg"]];
after retrieving value of enterprise logo
extract image url , request image using nsurlconnection, nsurlsession, or afnetworking.
e.g.
nsstring * __block imageurl = nil; nsarray * objects = [[self.details valueforkey:@"enterprise logo"] componentsseparatedbystring:@" "]; [objects enumerateobjectsusingblock:^(id object, nsuinteger index, bool *stop) { nsrange range = [object rangeofstring:@"src="]; if (range.location != nsnotfound) { imageurl = [object substringfromindex:range.location+range.length]; *stop = yes; } }];
Comments
Post a Comment