I need some help with an array that I am working on.
I am pulling back some data from a JSON query and writing it into an array, and then in a second loop I am writing that array into another array but I don’t know how to read the data back out??
This is the code:-
for (NSDictionary *weather in weatherarray)
{
int j = 1;
NSArray *hourlyArray = [weather objectForKey:@"hourly"];
for (NSDictionary *hourD in hourlyArray)
{
[multi addObject:Date];
[multi addObject:[hourD objectForKey:@"time"]];
[multi addObject:[hourD objectForKey:@"weatherCode"]];
[multi addObject:[hourD objectForKey:@"tempC"]];
[multi addObject:[hourD objectForKey:@"FeelsLikeC"]];
[multi addObject:[hourD objectForKey:@"chanceofrain"]];
[multi addObject:[hourD objectForKey:@"cloudcover"]];
[multi addObject:[hourD objectForKey:@"WindGustMiles"]];
[multi addObject:[hourD objectForKey:@"humidity"]];
[multi addObject:[hourD objectForKey:@"pressure"]];
j = j + 1;
}
[[multi1 objectAtIndex:j] addObject:multi];
i = i + 1;
}
NSLog(@"%@", [[[multi1 objectAtIndex:1] objectAtIndex:0] objectAtIndex:1]);
}
as you can see I am trying to read the data out at the end in an NSLog but i am struggling, with this. Can anyone help please??
You need to define and assign
multiwithin theforloop. So, put the lineabove the line
[multi addObject:Date]and move your lineabove the line
j = j + 1;. You don’t need thei = i + 1;here, unless you are doing something with it, that is outside the scope of this code fragment.Unless I have missed something, it should work like that.