2016-07-25 38 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