I have managed through tutorials to make http request and parse json object in obj-C. No from the data that I get I want to save the first 17 into an array and items from 20-33 to another. Problem is that data are not in the same order that appear to be if I do in http request but in another, so I cannot do that because they are not in the same order that should be.
Here is my code:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSLog(@"connectionDidFinishLoading");
NSLog(@"Succeeded! Received %d bytes of data",[self.responseData length]);
// convert to JSON
NSError *myError = nil;
NSDictionary *res = [NSJSONSerialization JSONObjectWithData:self.responseData options:NSJSONReadingMutableLeaves error:&myError];
NSMutableArray *array_1 = [NSMutableArray array];
NSMutableArray *array_2 = [NSMutableArray array];
int index=0;
// show all values
for(id key in res) {
index=index+1;
id value = [res objectForKey:key];
NSString *keyAsString = (NSString *)key;
NSString *valueAsString = (NSString *)value;
if (index<=17){
[array_1 addObject:valueAsString];
NSLog(@"%i: array 1 filling up: %@",index, keyAsString);
NSLog(@"%@",array_1);
} else if ((index>20)&&(index<=33)){
[array_2 addObject:valueAsString];
}
}
}
So I want my data to be in the same order that are when I run the script in my browser. I guess it has something to do with NSDictionary but I do not know what else to use.