Nick Lasta Nick Lasta - 10 months ago 22
iOS Question

IOS JSON - Getting unexpected results in the console

I'm new to JSON and trying to loop through my JSON Array like this

for (NSDictionary *dict in self.contentArray) {
NSLog(@"%@", dict);

But keep getting this type of content instead of the actual dictionary in the console:

<Content: 0x7fd9b1037950>

Here is my code that I used to Create the array:

// Create a new array to hold the locations
NSMutableArray *locations = [[NSMutableArray alloc] init];

// Get an array of dictionaries with the key "locations"
NSArray *array = [jsonDictionary objectForKey:@"data"];
// Iterate through the array of dictionaries
for(NSDictionary *dict in array) {
// Create a new Location object for each one and initialise it with information in the dictionary
Content *content = [[Content alloc] initWithJSONDictionary:dict];
// Add the Location object to the array
[locations addObject: content];


One of two things you can do to achieve the behaviour you wanted.

  1. Override the following method in your Content class

    (NSString *)description;

    And format and return the string as you wanted when instance of Content is printed using NSLog.

  2. Store the dict straightaway in your array without wrapping it around Content object then dictionary will get printed as you've expected.