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);
}
}];