zoukankan      html  css  js  c++  java
  • iOS AFN向接口端传递JSON数据

    NSDictionary *body = @{@"snippet": @{@"topLevelComment":@{@"snippet":@{@"textOriginal":self.commentToPost.text}},@"videoId":self.videoIdPostingOn}};
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:body options:0 error:&error];
    NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    
    AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
    
    NSMutableURLRequest *req = [[AFJSONRequestSerializer serializer] requestWithMethod:@"POST" URLString:[NSString stringWithFormat:@"https://www.googleapis.com/youtube/v3/commentThreads?part=snippet&access_token=%@",[[LoginSingleton sharedInstance] getaccesstoken]] parameters:nil error:nil];
    
    req.timeoutInterval= [[[NSUserDefaults standardUserDefaults] valueForKey:@"timeoutInterval"] longValue];
    [req setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [req setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [req setHTTPBody:[jsonString dataUsingEncoding:NSUTF8StringEncoding]];
    
    
    [[manager dataTaskWithRequest:req completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
    
        if (!error) {
            NSLog(@"Reply JSON: %@", responseObject);
    
            if ([responseObject isKindOfClass:[NSDictionary class]]) {
                  //blah blah
            }
        } else {
            NSLog(@"Error: %@, %@, %@", error, response, responseObject);
        }
    }] resume];
  • 相关阅读:
    UVa OJ 120
    ACM--string常见用法
    log4j
    总结13.11.9
    Java 动态生成 PDF 文件
    Linux_CentOS-服务器搭建 <七>
    关于dao层的封装和前端分页的结合(文章有点长,耐心点哦)
    Linux_CentOS-服务器搭建 <六>
    Linux_CentOS-服务器搭建 <五> 补充
    JQ获取CKeditor的值
  • 原文地址:https://www.cnblogs.com/wlsxmhz/p/5898129.html
Copyright © 2011-2022 走看看