JSON多值参数
JSON多值参数
// 1.URL
NSURL *url = [NSURL URLWithString:@"http://localhost:8080/MJServer/weather"];// 2.请求
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
// 3.请求方法
request.HTTPMethod = @"POST";
// 4.设置请求体(请求参数)
NSMutableString *param = [NSMutableString string];
[param appendString:@"place=beijing"];
[param appendString:@"&place=tianjin"];
[param appendString:@"&place=meizhou"];
request.HTTPBody = [param dataUsingEncoding:NSUTF8StringEncoding];
// 5.发送请求
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
if (data == nil || connectionError) return;
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
NSString *error = dict[@"error"];
if (error) {
[MBProgressHUD showError:error];
} else {
// NSArray *weathers = dict[@"weathers"];
NSLog(@"%@", dict);
}
}];
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。