1

有人可以帮我吗?我正在为 GET 和 POST 方法使用 NSURL 连接。reddit api 可以在这里找到:http ://www.reddit.com/dev/api#POST_api_subscribe

我对 ('sr', 'sr_name') 参数是什么感到特别困惑。它是某种数组吗?还是我必须通过“sr”或“sr_name”中的任何一个?

我当前的代码:

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.reddit.com/api/subscribe"]]];
    [request setHTTPMethod:@"POST"];


        request.HTTPBody = [[NSString stringWithFormat:@"api_type=json&action=%@&uh=%@&sr=%@", @"sub", modhashString, SubredditTitle] dataUsingEncoding:NSASCIIStringEncoding];


    NSURLResponse *response;

    NSError *error;

    NSData *POSTReply = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

    if (!error) {


        NSDictionary *json = [NSJSONSerialization
                              JSONObjectWithData:POSTReply
                              options:NSJSONReadingMutableContainers
                              error:nil];

        NSLog(@"%@", json);

        NSMutableArray *temp = [[json objectForKey:@"json"] objectForKey:@"errors"];

        if ([temp count] > 0){

            for (int i = 0; i<[temp count]; i++) {


                NSArray *temp2 = [[NSArray alloc] init];
                temp2 = [temp objectAtIndex:i];

                NSLog(@"Contains errors %@", temp2);

                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[temp2 objectAtIndex:1] message:nil delegate:self cancelButtonTitle:@":/" otherButtonTitles:nil, nil];

                [alert show];

            }
        }
        else{


        }
4

0 回答 0