I was able to parse a JSON and stored it in a NSMutableArray
named as json in my FirstViewController
. The problem is, I do not know how to access the array in my FirstViewController
from my View Controllers.
EDIT!!!
I moved the code from AppDelegate to my FirstViewController as it is not a good practice.
FirstViewController.h
#import <UIKit/UIKit.h>
@interface FirstViewController : UIViewController
{
NSMutableArray *jsonData;
}
@property (nonatomic, strong) NSMutableArray *jsonData;
@end
FirstViewController.m
@synthesize jsonData;
NSURL *url = [NSURL URLWithString:@"http://search.twitter.com/search.json?q=coredata"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
self.json = [NSJSONSerialization JSONObjectWithData:response options:0 error:&jsonParsingError];
SecondViewController *secondViewController = [[SecondViewController alloc] init];
secondViewController.secondJSON = [self jsonData];
[[self navigationController] pushViewController:secondViewController animated:YES];
SecondViewController.h
#import <UIKit/UIKit.h>
@interface SecondViewController : UIViewController
{
NSMutableArray *secondJSON;
}
@property (nonatomic, strong) NSMutableArray *secondJSON;
@end
SecondViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"%@", [self secondJSON]);
}
Output
2013-02-03 00:16:17.749 Subscription[24669:c07] (null)
Am I missing something?
Perhaps [[[UIApplication sharedApplication] delegate] json]
?
(And please, don't send synchronous requests on the main thread while the application is launching!)