0

I'm working in a simple IOS app with objective-c, and i want to load an image to the table cell. I have a litle web service that give me a json data like this:

[{"id":1,"name":"Papas","description":"Papas chilotas negras","images":
[{"url":"/uploads/product/images/1/8282486574_382f59c31e_o.jpg",  
"thumb":"url":"/uploads/product/images/1/
thumb_8282486574_382f59c31e_o.jpg"},
"catalog":"url":"/uploads/product/images/1/
catalog_8282486574_382f59c31e_o.jpg"},
"big":"url":"/uploads/product/images/1/
big_8282486574_382f59c31e_o.jpg"}}],
"price":1200,"stand_id":3,"created_at":"2017-10-
24T04:01:09.000Z","updated_at":"2017-10-24T04:01:09.000Z"}]

I had set up the name and description like this tableCell

The problem is how do i access the path to the thumb version of the image to show it in the table cell.

this is the code i have to populate the table

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];

NSDictionary *dictionary = [self.json objectAtIndex:indexPath.row];
cell.textLabel.text=[dictionary objectForKey:@"name"];
cell.detailTextLabel.text = [dictionary objectForKey:@"description"];
return cell;
}
3
  • Is this a valid JSON? Commented Oct 26, 2017 at 3:22
  • URL is invalid -> "thumb" : "url" : " /uploads/product/... /_o.jpg" <- never seen this type of json. So iam closing this post as a uncleared question. Commented Oct 26, 2017 at 4:04
  • the json data came from this url 18.221.78.126/ecoferia/api/products it came from a rails app with mysql db. Commented Oct 26, 2017 at 4:12

2 Answers 2

1

The JSON data that you gave is wrong. The right type is

("thumb" : "/uploads/product/images/1/thumb_8282486574_382f59c31e_o.jpg" ),

no "url".

So, you can get thumb images dictinary:

NSArray * arr = dictionary[@"images"];

such as

[arr[0] objectForKey:@"thumb"];
Sign up to request clarification or add additional context in comments.

Comments

0

The JSON in this link and the JSON you provided in you question is different.

According to the JSON in link, this is how you can parse it :

[[[[dictionary objectForKey:@"images"] objectAtIndex:0] valueForKey:@"thumb"] valueForKey:@"url"];

1 Comment

@AndresAldana Great. Please accept and upvote the answer then.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.