2016-07-25 99 views
-1

我是新来的JSON,并通过我的JSON数组这样IOS JSON - 获得意想不到的结果在控制台

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

试图循环,但继续得到这种类型的内容,而不是实际的字典在控制台:

<Content: 0x7fd9b1037950> 

这里是我的代码,我用来创建数组:

// 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]; 
    } 
+0

因为这就是你的数组中的实际情况。你是如何创建阵列的? – dan

+0

将代码编辑到您的问题中,以便它实际上可读。 – dan

+0

你正在得到预期的行为,你还期待什么?您正在存储一个内容对象并且获取它。 – ldindu

回答

1

一个两件事可以做到实现你想要的行为。

  1. 覆盖下面的方法,在内容类

    (NSString *)description; 
    

    和格式,并返回的字符串为你想要当使用NSLog的印刷内容的实例。

  2. 将字典直接存储在数组中,而不将其包装在内容对象中,然后字典将按照您的预期打印。

+0

我认为OP想要JSON输出,所以有比这更好的选择。 – Droppy