JSON多值參數
JSON多值參數
// 1.URL
NSURL*url = [NSURLURLWithString:@"http://localhost:8080/MJServer/weather"];
// 2.請求
NSMutableURLRequest*request = [NSMutableURLRequestrequestWithURL:url];
// 3.要求方法
request.HTTPMethod = @"POST";
// 4.佈建要求體(請求參數)
NSMutableString*param = [NSMutableStringstring];
[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);
}
}];