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