-1

JSON方法:

secdata = [NSString stringWithFormat:@"game_name=%@&game_desc=%@&start_date=%@",EGamename,Edescription,Estarttime,[NSNumber numberWithBool:YES]];


NSString *key = [NSString stringWithFormat:@"userid=%@&data=%@&step_name=%@&step_desc=%@&step_point=%@&hint_point=%@&hint=%@&step_location=%@&latitude=%@&longitude=%@&question=%@&answer=%@&options=%@&address=%@",useridpasstoeditgame,secdata,stepnameText.text,intotxt.text,steppointTxt.text,hintpenaltyTxt.text,hintText.text,locationTextfield.text,latitude,longitude,questionlbl.text,optionBlbl.text,locationTextfield.text,[NSNumber numberWithBool:YES]];

NSURL * url = [NSURL URLWithString:URL_PATH];

NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:url];

[request setHTTPMethod:@"POST"];
[request setHTTPBody:[key dataUsingEncoding:NSUTF8StringEncoding]];

connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
// this is for you to be able to get your server answer.
// you will need to make your class a delegate of NSURLConnectionDelegate and NSURLConnectionDataDelegate
myClassPointerData = [NSMutableData data] ;
4

1 回答 1

1

嘿,我在这里发布我对相同问题的答案,您可以在此处参考或我也将其粘贴在这里

如果你有space or spacial character你的代码而不是你必须做其他编码只是试试这个

NSString *string= [[NSString alloc]initWithFormat:@"url"];
        NSLog(@"%@",string);
        NSURL *url = [NSURL URLWithString:string];
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
        [request setHTTPMethod:@"POST"];

        NSURLResponse *response;
        NSError *err;
        NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
        NSLog(@"responseData: %@", responseData);
        NSString *str = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
        NSLog(@"responseData: %@", str);
        NSString *str1 = @"1";
        if ([str isEqualToString:str1 ])
        {

            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Successfully" message:@"" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
            [alert show];
        }
        else
        {
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Try Again" message:@"" delegate:self cancelButtonTitle:@"Try Later" otherButtonTitles:@"Call", nil];
            alert.tag = 1;
            [alert show];
        }

不需要使用 JSON,你可以在没有 JSON 的情况下以一种简单的方式做到这一点!!!

于 2013-08-21T11:12:45.517 回答