title: Nested JSONModel in iOS to get info from Instagram
body: <p>I'm working with <a href="https://github.com/icanzilb/JSONModel" rel="nofollow"><strong>JSONModel</strong></a> to parse Instagram info from JSON to a model in my iOS app. I have tried many ways to achieve it but I can't. Three main parts of the response are <strong>data</strong>, <strong>meta</strong> and <strong>pagination</strong>. I have created the model and the model is always NULL. I'm going to attach the response I'm trying to parse, my models and how I'm processing the response. I think it could be a problem with the structure but I don't know what I'm doing wrong. Thanks for your help.</p>
  
  <p><strong>Response from Instagram</strong></p>
  
  <pre><code>    {
      "data": [
          {
              "attribution": null,
              "caption": {
                  "created_time": "1387987595",
                  "from": {
                      "full_name": "Camilo Sacanamboy",
                      "id": "268167404",
                      "profile_picture": "http://images.ak.instagram.com/profiles/profile_268167404_75sq_1386784112.jpg",
                      "username": "csacanam"
                  },
                  "id": "618807262892627401",
                  "text": "Navidad :)"
              },
              "comments": {
                  "count": 2,
                  "data": [
                      {
                          "created_time": "1387987956",
                          "from": {
                              "full_name": "Luisa Bellydancer",
                              "id": "548519361",
                              "profile_picture": "http://images.ak.instagram.com/profiles/profile_548519361_75sq_1398196543.jpg",
                              "username": "luisacantillo"
                          },
                          "id": "618810289837938356",
                          "text": "Te amo beb\u00e9"
                      },
                      {
                          "created_time": "1403666639",
                          "from": {
                              "full_name": "Camilo Sacanamboy",
                              "id": "268167404",
                              "profile_picture": "http://images.ak.instagram.com/profiles/profile_268167404_75sq_1386784112.jpg",
                              "username": "csacanam"
                          },
                          "id": "750332614214522476",
                          "text": "#sacanamboy"
                      }
                  ]
              },
              "created_time": "1387987595",
              "filter": "Walden",
              "id": "618807262548694878_268167404",
              "images": {
                  "low_resolution": {
                      "height": 306,
                      "url": "http://scontent-b.cdninstagram.com/hphotos-xpf1/t51.2885-15/1515365_559830227444878_1414305160_a.jpg",
                      "width": 306
                  },
                  "standard_resolution": {
                      "height": 640,
                      "url": "http://scontent-b.cdninstagram.com/hphotos-xpf1/t51.2885-15/1515365_559830227444878_1414305160_n.jpg",
                      "width": 640
                  },
                  "thumbnail": {
                      "height": 150,
                      "url": "http://scontent-b.cdninstagram.com/hphotos-xpf1/t51.2885-15/1515365_559830227444878_1414305160_s.jpg",
                      "width": 150
                  }
              },
              "likes": {
                  "count": 2,
                  "data": [
                      {
                          "full_name": "Luisa Bellydancer",
                          "id": "548519361",
                          "profile_picture": "http://images.ak.instagram.com/profiles/profile_548519361_75sq_1398196543.jpg",
                          "username": "luisacantillo"
                      },
                      {
                          "full_name": "Steven Zambrano",
                          "id": "198842014",
                          "profile_picture": "http://photos-d.ak.instagram.com/hphotos-ak-xpa1/10354559_1419915091614315_879045002_a.jpg",
                          "username": "steven_zambrano"
                      }
                  ]
              },
              "link": "http://instagram.com/p/iWce08pZde/",
              "location": null,
              "tags": [
                  "sacanamboy"
              ],
              "type": "image",
              "user": {
                  "bio": "",
                  "full_name": "Camilo Sacanamboy",
                  "id": "268167404",
                  "profile_picture": "http://images.ak.instagram.com/profiles/profile_268167404_75sq_1386784112.jpg",
                  "username": "csacanam",
                  "website": ""
              },
              "users_in_photo": [
                  {
                      "position": {
                          "x": 0.39722222,
                          "y": 0.15416667
                      },
                      "user": {
                          "full_name": "Luisa Bellydancer",
                          "id": "548519361",
                          "profile_picture": "http://images.ak.instagram.com/profiles/profile_548519361_75sq_1398196543.jpg",
                          "username": "luisacantillo"
                      }
                  },
                  {
                      "position": {
                          "x": 0.55138886,
                          "y": 0.09583333
                      },
                      "user": {
                          "full_name": "Camilo Sacanamboy",
                          "id": "268167404",
                          "profile_picture": "http://images.ak.instagram.com/profiles/profile_268167404_75sq_1386784112.jpg",
                          "username": "csacanam"
                      }
                  }
              ]
          },
          {
              "attribution": null,
              "caption": {
                  "created_time": "1391910835",
                  "from": {
                      "full_name": "Camilo Sacanamboy",
                      "id": "268167404",
                      "profile_picture": "http://images.ak.instagram.com/profiles/profile_268167404_75sq_1386784112.jpg",
                      "username": "csacanam"
                  },
                  "id": "651717783438333290",
                  "text": "Vista de Bogot\u00e1"
              },
              "comments": {
                  "count": 1,
                  "data": [
                      {
                          "created_time": "1403665438",
                          "from": {
                              "full_name": "Camilo Sacanamboy",
                              "id": "268167404",
                              "profile_picture": "http://images.ak.instagram.com/profiles/profile_268167404_75sq_1386784112.jpg",
                              "username": "csacanam"
                          },
                          "id": "750322542532990878",
                          "text": "#sacanamboy"
                      }
                  ]
              },
              "created_time": "1391910835",
              "filter": "Hudson",
              "id": "651717782742079012_268167404",
              "images": {
                  "low_resolution": {
                      "height": 306,
                      "url": "http://scontent-b.cdninstagram.com/hphotos-xfp1/t51.2885-15/1889287_611340528913277_403885343_a.jpg",
                      "width": 306
                  },
                  "standard_resolution": {
                      "height": 640,
                      "url": "http://scontent-b.cdninstagram.com/hphotos-xfp1/t51.2885-15/1889287_611340528913277_403885343_n.jpg",
                      "width": 640
                  },
                  "thumbnail": {
                      "height": 150,
                      "url": "http://scontent-b.cdninstagram.com/hphotos-xfp1/t51.2885-15/1889287_611340528913277_403885343_s.jpg",
                      "width": 150
                  }
              },
              "likes": {
                  "count": 3,
                  "data": [
                      {
                          "full_name": "Luisa Bellydancer",
                          "id": "548519361",
                          "profile_picture": "http://images.ak.instagram.com/profiles/profile_548519361_75sq_1398196543.jpg",
                          "username": "luisacantillo"
                      },
                      {
                          "full_name": "Stiven Sepulveda Casta\u00f1o",
                          "id": "270408040",
                          "profile_picture": "http://photos-a.ak.instagram.com/hphotos-ak-xfp1/10354393_1459814907595448_1770710968_a.jpg",
                          "username": "johntato"
                      },
                      {
                          "full_name": "Julian Garcia",
                          "id": "318551590",
                          "profile_picture": "http://photos-e.ak.instagram.com/hphotos-ak-xaf1/10413240_284995708339980_626057267_a.jpg",
                          "username": "juliangarcia20"
                      }
                  ]
              },
              "link": "http://instagram.com/p/kLXd7WJZYk/",
              "location": {
                  "id": 1187760,
                  "latitude": 4.67413252,
                  "longitude": -74.037993338,
                  "name": "Mirador de La Calera, Bogota"
              },
              "tags": [
                  "sacanamboy"
              ],
              "type": "image",
              "user": {
                  "bio": "",
                  "full_name": "Camilo Sacanamboy",
                  "id": "268167404",
                  "profile_picture": "http://images.ak.instagram.com/profiles/profile_268167404_75sq_1386784112.jpg",
                  "username": "csacanam",
                  "website": ""
              },
              "users_in_photo": [
                  {
                      "position": {
                          "x": 0.3625,
                          "y": 0.54444444
                      },
                      "user": {
                          "full_name": "Luisa Bellydancer",
                          "id": "548519361",
                          "profile_picture": "http://images.ak.instagram.com/profiles/profile_548519361_75sq_1398196543.jpg",
                          "username": "luisacantillo"
                      }
                  },
                  {
                      "position": {
                          "x": 0.60694444,
                          "y": 0.42222223
                      },
                      "user": {
                          "full_name": "Camilo Sacanamboy",
                          "id": "268167404",
                          "profile_picture": "http://images.ak.instagram.com/profiles/profile_268167404_75sq_1386784112.jpg",
                          "username": "csacanam"
                      }
                  }
              ]
          }
      ],
      "meta": {
          "code": 200
      },
      "pagination": {
          "deprecation_warning": "next_max_id and min_id are deprecated for this endpoint; use min_tag_id and max_tag_id instead",
          "min_tag_id": "1403666639684031",
          "next_min_id": "1403666639684031"
      }
  }
  </code></pre>
  
  <p><strong>Models</strong></p>
  
  <pre><code>    @interface TagPicturesInstagram : JSONModel
      @property (strong,nonatomic) NSArray&lt;PictureInstagram&gt; *data;
      @property (strong,nonatomic) MetaInstagram *meta;
      @property (strong,nonatomic) PaginationInstagram *pagination;
      @end
  
      @protocol PictureInstagram
      @end
      @interface PictureInstagram : JSONModel
      @property (strong,nonatomic) NSString&lt;Optional&gt; *attribution;
      @property (strong,nonatomic) CaptionInstagram *caption;
      @property (strong,nonatomic) CommentsInstagram *comments;
      @property (strong,nonatomic) NSString *created_time;
      @property (strong,nonatomic) NSString *filter;
      @property (strong,nonatomic) NSString *id;
      @property (strong,nonatomic) ImagesInstagram *images;
      @property (strong,nonatomic) LikesInstagram *likes;
      @property (strong,nonatomic) NSString *link;
      @property (strong,nonatomic) LocationInstagram&lt;Optional&gt; *location;
      @property (strong,nonatomic) NSArray&lt;Optional&gt; *tags;
      @property (strong,nonatomic) NSString *type;
      @property (strong,nonatomic) UserInstagram *user;
      @property (strong,nonatomic) NSArray&lt;UserInPhoto&gt; *users_in_photo;
      //@property (assign,nonatomic) BOOL user_has_liked;
      //@property (strong,nonatomic) NSString&lt;Optional&gt; *website;
      @end
  
      @interface MetaInstagram : JSONModel
      @property (assign,nonatomic) int code;
      @property (strong,nonatomic) NSString&lt;Optional&gt; *error_type;
      @property (strong,nonatomic) NSString&lt;Optional&gt; *error_message;
      @end
  
      @interface PaginationInstagram : JSONModel
      @property (strong,nonatomic) NSString&lt;Optional&gt; *next_max_tag_id;
      @property (strong,nonatomic) NSString&lt;Optional&gt; *deprecation_warning;
      @property (strong,nonatomic) NSString&lt;Optional&gt; *next_max_id;
      @property (strong,nonatomic) NSString&lt;Optional&gt; *next_min_id;
      @property (strong,nonatomic) NSString&lt;Optional&gt; *min_tag_id;
      @property (strong,nonatomic) NSString&lt;Optional&gt; *next_url;
      @end
  
      @interface CaptionInstagram : JSONModel
      @property (strong,nonatomic) NSString *created_time;
      @property (strong,nonatomic) FromInstagram *from;
      @property (strong,nonatomic) NSString *id;
      @property (strong,nonatomic) NSString&lt;Optional&gt; *text;
      @end
  
      @interface CommentsInstagram : JSONModel
      @property (assign,nonatomic) int count;
      @property (strong,nonatomic) NSArray&lt;CommentInstagram&gt; *data;
      @end
  
  
      @interface ImagesInstagram : JSONModel
      @property (strong,nonatomic) ImgInstagram *low_resolution;
      @property (strong,nonatomic) ImgInstagram *standard_resolution;
      @property (strong,nonatomic) ImgInstagram *thumbnail;
      @end
  
      @interface LikesInstagram : JSONModel
      @property (assign,nonatomic) int count;
      @property (strong,nonatomic) NSArray&lt;FromInstagram&gt; *data;
      @end
  
      @interface LocationInstagram : JSONModel
      @property (assign,nonatomic) int id;
      @property (assign,nonatomic) double latitude;
      @property (assign,nonatomic) double longitude;
      @property (strong,nonatomic) NSString *name;
      @end
  
      @interface UserInstagram : JSONModel
      @property (strong,nonatomic) NSString&lt;Optional&gt; *bio;
      @property (strong,nonatomic) NSString *full_name;
      @property (strong,nonatomic) NSString *id;
      @property (strong,nonatomic) NSString *profile_picture;
      @property (strong,nonatomic) NSString *username;
      @property (strong,nonatomic) NSString&lt;Optional&gt; *website;
      @end
  
      @interface UserInPhoto : JSONModel
      @property (strong,nonatomic) PositionTagInstagram *position;
      @property (strong,nonatomic) FromInstagram *user;
      @end
  
      @protocol FromInstagram
      @end
      @interface FromInstagram : JSONModel
      @property (strong,nonatomic) NSString *full_name;
      @property (strong,nonatomic) NSString *id;
      @property (strong,nonatomic) NSString *profile_picture;
      @property (strong,nonatomic) NSString *username;
      @end
  
      @protocol CommentInstagram
      @end
      @interface CommentInstagram : JSONModel
      @property (strong,nonatomic) NSString *created_time;
      @property (strong,nonatomic) FromInstagram *from;
      @property (strong,nonatomic) NSString *id;
      @property (strong,nonatomic) NSString *text;
      @end
  
      @protocol ImgInstagram
      @end
      @interface ImgInstagram : JSONModel
      @property (assign,nonatomic) double height;
      @property (strong,nonatomic) NSString *url;
      @property (assign,nonatomic) double width;
      @end
  
      @interface PositionTagInstagram : JSONModel
      @property (assign,nonatomic) double x;
      @property (assign,nonatomic) double y;
      @end
  </code></pre>
  
  <p><strong>Getting response with <a href="https://github.com/AFNetworking/AFNetworking" rel="nofollow">AFNetworking</a></strong></p>
  
  <pre><code>-(void) loadInstagramInfo
  {
      //1. Create request
      NSString *string = [NSString stringWithFormat:@"%@", BaseURLString];
      NSURL *url = [NSURL URLWithString:string];
      NSURLRequest *request = [NSURLRequest requestWithURL:url];
  
      //2. Do request with AFNetworking
      AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
      operation.responseSerializer = [AFJSONResponseSerializer serializer];
      [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
          NSString *json = [responseObject description];
          NSError *err = nil;
          self.pictures = [[TagPicturesInstagram alloc]initWithString:json error:&amp;err];
      } failure:^(AFHTTPRequestOperation *operation, NSError *error)
      {
          NSLog(@"Error cargando fotos");
          /*
           UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error Retrieving Weather"
           message:[error localizedDescription]
           delegate:nil
           cancelButtonTitle:@"Ok"
           otherButtonTitles:nil];
           [alertView show];*/
      }];
  
      [operation start];
  }
  </code></pre>