JSON数据请求

NSError *error;

//加载一个NSURL对象

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:URL]];

//将请求的URL数据放到NSData对象中

NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

if (response != nil) {

NSMutableDictionary *dict = nil;

dict = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];

for (NSString *item in dict[@"s_province"]) {

[self.provinceArray addObject:item];

}

[self.myPicker reloadAllComponents];

}

你可能感兴趣的:(JSON数据请求)