JSON多值参数

页面导航:首页 > 网络编程 > JavaScript > JSON多值参数

JSON多值参数

来源: 作者: 时间:2016-02-05 11:06 【

JSON多 20540;参数 1 URLNSURL*url = [NSURLURLWithString:@ http: localhost:8080 MJServer weather ]; 2 请求NSMutableURLRequest*request = [NSMutableURLRequestrequestWithURL:url]

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

文章评论

最 近 更 新
热 点 排 行
Js与CSS工具
代码转换工具

<