JSON を解析して、NSMutableArray
.json という名前のファイルに保存することができましたFirstViewController
。FirstViewController
問題は、 View Controller から自分の配列にアクセスする方法がわからないことです。
編集!!!
コードを AppDelegate から FirstViewController に移動したのは、適切な方法ではないためです。
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]);
}
出力
2013-02-03 00:16:17.749 Subscription[24669:c07] (null)
何か不足していますか?