-2

检查 self.weatherData 时,即使“数据”中有数据,我什么也得不到。这是我的功能:

- (void)handleNetworkResponse:(NSData *)myData
{
    //NSMutableDictionary *data = [NSMutableDictionary dictionary];
    NSMutableDictionary *data = [[NSMutableDictionary alloc] init];

    // now we'll parse our data using NSJSONSerialization
    id myJSON = [NSJSONSerialization JSONObjectWithData:myData options:NSJSONReadingMutableContainers error:nil];

    // typecast an array and list its contents
    NSDictionary *jsonArray = (NSDictionary *)myJSON;

    // take a look at all elements in the array
    for (id element in jsonArray) {

        id key = [element description];

        id innerArr = [jsonArray objectForKey:key];

        NSDictionary *inner = (NSDictionary *)innerArr;

        if ([inner conformsToProtocol:@protocol(NSFastEnumeration)]) {

            for(id ele in inner) {

                id innerKey = [ele description];
                [data setObject:[[inner valueForKey:innerKey] description] forKey:[ele description]];
            }
        }
        else {

            [data setObject:[inner description] forKey:[element description]];
        }
    }

    NSLog([data description]);
    self.weatherData = data;
}

但是,当检查 self.weatherData 时,即使“数据”中有数据,我什么也得不到。

4

1 回答 1

0

问题是当我从异步方法将数据分配给变量时,数据不存在:D 现在通过添加委托回调来解决所有问题

于 2013-08-29T22:48:52.923 回答