Objective-C Xcode Workbench ตอน พื้นฐาน การใช้ JSON

Web Service JSON : json.php

[“http://www.yensaby.com/images/json/img1.png”,
“http://www.yensaby.com/images/json/img2.png”,
“http://www.yensaby.com/images/json/img3.png”,
“http://www.yensaby.com/images/json/img4.png”,
“http://www.yensaby.com/images/json/img5.png”]

Model Controller : View Did Load

NSString *urlString = [NSString stringWithFormat:@”http://www.yensaby.com/json.php”];

NSURL *url = [NSURL URLWithString:urlString];

NSData *data = [NSData dataWithContentsOfURL:url];

NSError *error;

NSMutableDictionary *json = [NSJSONSerialization JSONObjectWithData:Ddata options:kNilOptions error:&error];

NSLog(@”%@”, [json objectAtIndex:0]);

NSString *imageString = [NSString stringWithFormat:@”%@”, [json objectAtIndex:0];

NSURL *urlOne = [NSURL URLWithString:imageString];

NSData *newData = [NSData dataWithContentsOfURL:urlone];

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];

[imageView setImage:[UIImage imageWithData:newData]];

[self.view addSubview:imageView];

 

Leave a Reply

อีเมลของคุณจะไม่แสดงให้คนอื่นเห็น