【发布时间】:2016-07-25 21:50:22
【问题描述】:
我是 JSON 新手,并试图像这样遍历我的 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];
}
【问题讨论】:
-
因为这就是您的阵列中的实际内容。你是如何创建数组的?
-
将代码编辑到您的问题中,使其真正可读。
-
你得到了预期的行为,你还期待什么?您正在存储一个内容对象并获得它。
-
以为我会收到这样的东西:
-
@ldindu { "section" : "0", "ch1" : "", "ch2" : "", "description": "" },
标签: ios objective-c json nsmutablearray nsmutabledictionary