我想从我的 void 方法中获取 json 字符串,让我们看看
-(void) getIDfromMarket{}
我想从 getIDfromMarket 显示结果 json 并且它已经成功了,现在我想将它传递给
-(void)viewDidLoad
怎么做?这是我的代码
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self getIDfromMarket];
NSLog(@"ID==",ID);
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//////get global market From JSOn
-(void) getIDfromMarket{
NSError *error = nil;
///set params url to get market localization
NSData *jsonData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://someurl"]];
if (jsonData) {
id jsonObjects = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
NSArray *Market = [jsonObjects objectForKey:@"market"];
NSLog(@"%@", Market);
if(Market==NULL){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Oh Snap!" message:@"Can't Get Market ID " delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}
}
else{
NSLog(@"Error Fetch Market ID");
}
}
@end
我不想登录NSLog(@"%@", Market);
viewDidLoad,怎么办?