以下のコードは以前は機能していましたが、突然機能しなくなりました。誰かが私が間違っていることを教えてもらえますか?
の出力NSLog()
:
2013-05-14 16:06:35.475 Run.PH[1502:19a03] background = (null)
2013-05-14 16:06:35.476 Run.PH[1502:19a03] logo = (null)
2013-05-14 16:06:35.476 Run.PH[1502:19a03] json = (null)
2013-05-14 16:06:35.476 Run.PH[1502:19a03] welcome = (null)
コード:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString *urlString = [NSString stringWithFormat:@"http://run.ph/json/test_json_dyna.jsp"];
NSURL *url = [NSURL URLWithString:urlString];
NSData *data = [NSData dataWithContentsOfURL:url];
if(data != nil)
{
NSError *error;
_json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
_welcomeMessage.text = [[_json objectForKey:@"welcome"] objectForKey:@"message"];
NSString *background = [[_json objectForKey:@"welcome"] objectForKey:@"background"];
NSString *logo = [[_json objectForKey:@"welcome"] objectForKey:@"logo"];
NSLog(@"background = %@", background);
NSLog(@"logo = %@", logo);
NSLog(@"json = %@", _json);
NSLog(@"welcome = %@", _welcomeMessage.text);
NSURL *urlBackground = [NSURL URLWithString:background];
NSData *dataBackground = [NSData dataWithContentsOfURL:urlBackground];
[_background setImage:[UIImage imageWithData:dataBackground]];
NSURL *urlLogo = [NSURL URLWithString:logo];
NSData *dataLogo = [NSData dataWithContentsOfURL:urlLogo];
[_logo setImage:[UIImage imageWithData:dataLogo]];
}
else
{
NSLog(@"Error!");
}
[self.view reloadInputViews];
}